[Math] Check if an ellipse is within another ellipse

conic sectionseuclidean-geometrygeometry

I have an ellipse $E_1$ centered at $(h,k)$, with semi-major axis $r_x$, semi-minor axis $r_y$, both aligned with the Cartesian plane.

How do I determine if another ellipse $E_2$ is within this given ellipse $E_1$?

$E_2$ can be anywhere in the Cartesian plane. What is given, is the centerpoint at $(i,j)$, the semi-major axis $r_x$ and the semi-minor axis $r_y$ and a rotation angle $\alpha$ (can be $0$, so no rotation).

I need this for a computed algorithm.
Given this computer science background, what i use right now is the formula from here, and choose a point on the ellipse $E_2$, check if its within $E_1$ and choose another point, $1°$ further and check that point again and so on, until i complete $360°$.

I was thinking, that there has to be a better solution, a more formal and complete one (i think it should be possible to get a wrong result with the current algorithm in some very special cases).
Yet, i haven't found a better solution.

Best Answer

Hint:

Without loss of generality, one of the ellipses is the unit circle centered at the origin. (If not, you can translate its center to the origin, counter-rotate to bring its major axis horizontal and rescale non-isotropically by the axis lengths).

Then the problem reduces to checking if an ellipse is wholly contained in the unit circle.

Let the parametric equation of that ellipse be

$$\vec p=\vec p_c+\vec a\cos t+\vec b\sin t.$$ We need to guarantee the inequality

$$\vec p^2\le 1,$$ i.e.

$$\vec p_c^2+\vec a^2\cos^2t+\vec b^2\sin^2t+2\vec p_c\vec a\cos t+2\vec p_c\vec b\sin t\le 1$$ (we have $\vec a\vec b=0$).

The inequality is ensured by finding the maxima of the trigonometric polynomial and showing the they don't exceed $1$.

Unfortunately, this leads to a quartic equation, so that an analytical solution promises to be painful. The problem is very close to that of finding the shortest distance of a point to an ellipse, or to ellipse offsetting.


There is an analytical solution, but it is a little scary.

  • by an affine transform, stretch the plane so that the contained ellipse becomes a circle, while the containing ellipse becomes centered at the origin and axis-aligned, hence of the form

$$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1.$$

  • "deflate" the circle while you "inflate" the ellipse; that means that you reduce the radius of the circle until it reduces to a point, while you compute the corresponding offset curve of the ellipse (https://en.wikipedia.org/wiki/Parallel_curve).

  • the offset curve has a known implicit equation, given in "Brief Atlas of Offset Curves, Juana Sandra", available online.

enter image description here

  • the point is contained in the offset curve, hence the circle in the ellipse, when the implicit expression has the desired sign.