def radialrange(self, origin, return_all_global_extrema=False):
"""returns the tuples (d_min, t_min) and (d_max, t_max) which minimize
and maximize, respectively, the distance,
d = |self.point(t)-origin|."""
u1orig = self.u1transform(origin)
if abs(u1orig) == 1: # origin lies on ellipse
t = self.phase2t(phase(u1orig))
d_min = 0
# Transform to a coordinate system where the ellipse is centered
# at the origin and its axes are horizontal/vertical
zeta0 = self.centeriso(origin)
a, b = self.radius.real, self.radius.imag
x0, y0 = zeta0.real, zeta0.imag
# Find t s.t. z'(t)
a2mb2 = (a**2 - b**2)
if u1orig.imag: # x != x0
coeffs = [a2mb2**2,
2*a2mb2*b**2*y0,
(-a**4 + (2*a**2 - b**2 + y0**2)*b**2 + x0**2)*b**2,
-2*a2mb2*b**4*y0,
-b**6*y0**2]
ys = polyroots(coeffs, realroots=True,
condition=lambda r: -b <= r <= b)
xs = (a*sqrt(1 - y**2/b**2) for y in ys)
ts = [self.phase2t(phase(self.u1transform(self.icenteriso(
complex(x, y))))) for x, y in zip(xs, ys)]
else: # This case is very similar, see notes and assume instead y0!=y
b2ma2 = (b**2 - a**2)
coeffs = [b2ma2**2,
2*b2ma2*a**2*x0,
(-b**4 + (2*b**2 - a**2 + x0**2)*a**2 + y0**2)*a**2,
-2*b2ma2*a**4*x0,
-a**6*x0**2]
xs = polyroots(coeffs, realroots=True,
condition=lambda r: -a <= r <= a)
ys = (b*sqrt(1 - x**2/a**2) for x in xs)
ts = [self.phase2t(phase(self.u1transform(self.icenteriso(
complex(x, y))))) for x, y in zip(xs, ys)]
raise _NotImplemented4ArcException
评论列表
文章目录