<<

Dr Robert N¨urnberg, Imperial College London Copyright c 2006. All Rights Reserved. www.ma.ic.ac.uk/~rn/distance2ellipse.pdf Distance from a Point to an Ellipse

Let ~p = (x, y) ∈ R2. Let the ellipse, which is assumed to be centred at the origin, be given by the parameterization ~x(θ) := r (α cos θ, β sin θ)T , or equivalently by the x 2 y 2 2 ( α ) + ( β ) = r . A necessary condition for ~x to be the closest point to ~p is that ~p − ~x is to the vector in ~x, i.e. (~p − ~x(θ)) . ~x0(θ) = 0. This gives f(θ) := (α2 − β2) r cos θ sin θ − x α sin θ + y β cos θ = 0 . The above equation can be solved with a Newton method, where one notes that f 0(θ) = (α2 − β2) r (cos2 θ − sin2 θ) − x α cos θ − y β sin θ. (0) −1 α y With the initial guess θ = tan ( β x ) ≡ atan2(α y,β x), the iteration always converges in practice, usually taking only a couple of iterations. Of course, the desired distance is then given by |~p − ~x(θ)|.

Distance from a Point to an

The same idea generalizes to 3d. Let ~p = (x, y, z) ∈ R3 and let the ellipsoid, which is again assumed to be centred at the origin, be given by the parameterization α cos φ cos θ ~x(θ, φ) := r β cos φ sin θ , γ sin φ or equivalently by the equation x 2 y 2 z 2 2 ( α ) + ( β ) + ( γ ) = r . A necessary condition for ~x to be the closest point to ~p is that ~p − ~x is perpendicular to the tangent in ~x, i.e. ∂~x ∂~x (~p − ~x) . = 0, (~p − ~x) . = 0 . ∂θ ∂φ This gives 0 = (α2 − β2) r cos θ sin θ cos φ − x α sin θ + y β cos θ, 0 = (α2 cos2 θ + β2 sin2 θ − γ2) r sin φ cos φ − x α sin φ cos θ − y β sin φ sin θ + z γ cos φ. The above system 0 = F (θ, φ) can be solved with a Newton method, where one notes that 2×2 DF (θ, φ) = (aij) ∈ R is given by 2 2 2 2 a11 = (α − β ) r (cos θ − sin θ) cos φ − x α cos θ − y β sin θ, 2 2 a12 = −(α − β ) r cos θ sin θ sin φ, 2 2 a21 = −2 (α − β ) r cos θ sin θ sin φ cos φ + x α sin φ sin θ − y β sin φ cos θ, 2 2 2 2 2 2 2 a22 = (α cos θ + β sin θ − γ ) r (cos φ − sin φ) − x α cos φ cos θ − y β cos φ sin θ − z γ sin φ

α y x y 1 (0) (0) −1 −1 2 2 2 With the initial guess (θ , φ ) = (tan ( β x ), tan (z/[γ (( α ) +( β ) ) ])) ≡ (atan2(α y,β x), x y 1 2 2 2 atan2(z,γ (( α ) + ( β ) ) )), the iteration always converges in practice, usually taking only a couple of iterations to converge, with the desired distance given by |~p − ~x(θ, φ)|. This is a significant advantage over other published methods. See e.g. www.geometrictools.com/Documentation/DistancePointToEllipsoid.pdf by David Eberly, where a possibly ill-conditioned sixth degree polynomial needs to be solved.