Check if an ellipse is within another ellipse 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.
 A: 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.



*

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

A: Hint :
In the general case (any position of center, any length of axes, any angle of orientation) for both ellipses :
Express the equations of the ellipses on the general form :
$$y^2+A_1xy+B_1x^2+C_1y+D_1x+F_1=0  \qquad\qquad \text{Ellipse } E_1$$
$$y^2+A_2xy+B_2x^2+C_2y+D_2x+F_2=0  \qquad\qquad \text{Ellipse } E_1$$
For example if $E_1$ is centered at $(h,k)$, with semi-major axis $r_x$, semi-minor axis $r_y$, both aligned with the Cartesian plane :
$$\left(\frac{y-k}{r_y}\right)^2+\left(\frac{x-h}{r_x}\right)^2=1$$
$A_1=0\quad;\quad  B_1=\left(\frac{r_y}{r_x}\right)^2\quad ;\quad C_1=2k \quad;\quad  D_1=-2h\left(\frac{r_y}{r_x}\right)^2 \quad;\quad  F_1=k^2+h^2\left(\frac{r_y}{r_x}\right)^2-1$
Do the same for the parameters of $E_2$
Of course, it is a bit more complicated if the axes of the ellipses are not parallel to the Cartesian axes.
So, at this point, the numerical values of the ten coefficients are known.
Solve for $(x,y)$ (with numerical calculus) the system of equations :
$$\begin{cases}
y^2+A_1xy+B_1x^2+C_1y+D_1x+F_1=0  \\
y^2+A_2xy+B_2x^2+C_2y+D_2x+F_2=0 
\end{cases}$$
Four roots $(x,y)$ are obtained (real and\or complex).
The result is : $\begin{cases}
\text{Case 1 : If  one or more root is real, the ellipses intersect.} \\
\text{Case 2 : If all roots are complex, see case below:} \\
\end{cases}$
In case 2, determine if the center of $E_2$ is outside $E_1$.  And  determine if the center of $E_2$ is outside $E_1$. If both are outside, the two ellipses are outside each other. If not, one is inside the other.
NOTE :
To determine if a point $(x,y)$ is outside $E_1$, compute 
$$\quad G_1=y^2+A_1xy+B_1x^2+C_1y+D_1x+F_1$$
If $G_1>0$ the point is outside.
Similarly to determine if a point is outside $E_2$ .
A: First, express $E_2$ in cartesian coordinates $(x,y)$. Then substitute $X=\dfrac{x+h}{r_x},Y=\dfrac{y+k}{r_y}$. This substitution transforms $E_1$ to the unit circle centred at the origin, so the problem reduces to deciding whether the transformed ellipse $E_2'$ is contained in this unit circle.
To do this, you can use Lagrange multipliers to maximise $X^2+Y^2$ subject to the transformed equation of $E_2'$. I don't have time for this at the moment, but I don't foresee any problems.
Edited to add: I have tried to work through the Lagrange multiplier solution, and unfortunately it doesn't look any easier than the solutions proposed in other answers.
