def _intersect_elipsis(self, center, radius, x):
""" upper intersection of line parallel to y axis and an ellipsis
where line is given by x origin
circle by center, radius.x and radius.y semimajor and seminimor axis (half width and height) as float
return float y of upper intersection point, float angle
"""
dx = x - center.x
d2 = dx * dx
A = 1 / radius.y / radius.y
C = d2 / radius.x / radius.x - 1
d = - 4 * A * C
if d <= 0:
if x > center.x:
return center.y, 0
else:
return center.y, pi
else:
y0 = sqrt(d) / 2 / A
d = (radius.x * radius.x) - d2
y = sqrt(d)
return center.y + y0, atan2(y, dx)
评论列表
文章目录