Given a point p exterior to an axially aligned, origin centered ellipse E, find the (upto) four unique normals to E passing through p.
This is not a Mathematica question. Direct computation is too slow; I am willing to sacrifice precision and accuracy for speed.
I have searched the web, but all I found involved overly complex calculations which if implemented directly appear to lack the performance I need. Is there a more "programmatical" way to do this, like using matrices or scaling the ellipse into a circle?
Let's assume the ellipse
E
is in "standard position", center at the origin and axes parallel to the coordinate axes:The boundary cases
a=b
are circles, where the normal lines are simply ones that pass through the center (origin) and are thus easy to find. So we omit discussion of these cases.The slope of the tangent to the ellipse at any point
(x,y)
may be found by implicit differentiation:For the line passing through (x,y) and a specified point
p = (u,v)
not on the ellipse, that is normal to ellipseE
when its slope is the negative reciprocal ofdy/dx
:which simplifies to:
In this form we recognize it is the equation for a right rectangular hyperbola. Depending on how many points of intersection there are between the ellipse and the hyperbola (2,3,4), we have that many normals to
E
passing throughp
.By reflected symmetry, if
p
is assumed exterior toE
, we may takep
to be in the first quadrant:We could have boundary cases where
u=0
orv=0
, i.e. pointp
lies on an axis ofE
, but these cases may be reduced to solving a quadratic, because two normals are the (coinciding) lines through the endpoints of that axis. We defer further discussion of these special cases for the moment.Here's an illustration with
a=u=5,b=v=3
in which only one branch of the hyperbola intersectsE
, and there will be only two normals:If the system of two equations in two unknowns
(x,y)
is reduced to one equation in one unknown, the simplest root-finding method to code is a bisection method, but knowing something about the possible locations of roots/intersections will expedite our search. The intersection in the first quadrant is the nearest point ofE
top
, and likewise the intersection in the third quadrant is the farthest point ofE
fromp
. If the pointp
were a good bit closer to the upper endpoint of the minor axis, the branches of the hyperbola would shift together enough to create up to two more points of intersection in the fourth quadrant.One approach would be to parameterize
E
by points of intersection with the x-axis. The lines fromp
normal to the ellipse must intersect the major axis which is a finite interval[-a,+a]
. We can test both the upper and lower points of intersectionq=(x,y)
of a line passing throughp=(u,v)
and(z,0)
asz
sweeps from-a
to+a
, looking for places where the ellipse and hyperbola intersect.In more detail:
Once a subinterval is detected (either for upper or lower portion) where the sign changes, it can be refined to get the desired accuracy. If only modest accuracy is needed, there may be no need to use faster root finding methods, but even if they are needed, having a short subinterval that isolates a root (or root pair in the fourth quadrant) will be useful.
** more to come comparing convergence of various methods **