# How to calculate minimum distance between two arbitrary ellipses in 2D?

Arbitrary ellipses means that they can be scaled, translated and rotated in any way in 2D. Do you know some high-school method (might be slightly more advanced than that) to find the minimum distance? I'd love a symbolic expression/solution but a numerical solution for a specific pair of ellipses would be greatly appreciated too.Thanks very much for any solution.

-
 possible duplicate of minimum distance between two ellipses – joriki Sep 12 '12 at 13:38

In general, an ellipse is given by $$G(x,y)=a x^2 + b y^2 + c x y + d x + e y + f =0.$$
Let us denote the two ellipses with the subscripts 1 and 2. As we would like to minimize the square distance $d^2=(x_1 - x_2)^2 + (y_1 + y_2)^2$ between the two ellipses. We use the method of Lagrange multiplier and write $G = d^2 + \lambda_1 G_1(x_1,y_1) + \lambda_2 G_2(x_2,y_2)$ with the conditions for an extremum $$\partial_{x_1} G = 2 (x_1 - x_2) + λ_1(2 a_1 x_1+ c_1 y_1 +d_1) =0,$$ $$\partial_{y_1} G =2 (y_1 - y_2) + λ_2(2 b_1 y_1+ c_1 x_1 +e_1) =0,$$ $$\partial_{x_2} G = 2 (x_2 - x_1) + λ_1(2 a_2 x_2+ c_2 y_2 +d_2) =0,$$ and $$\partial_{y_2} G =2 (y_2 - y_1) + λ_2(2 b_2 y_2+ c_2 x_2 +e_2) =0.$$ Together with the conditions $G_1 = G_2 =0$, we have 6 equations for 6 unknowns (though some are not linear but quadratic). We can "easily" solve for $x_1,y_1,x_2,y_2,\lambda_1,\lambda_2$. Plugging the different solutions into the expression for $d^2$, we can select the one that minimizes the distance.
In general, I think you'd end up solving a polynomial of degree $12$, so numerical methods will be needed. Certainly it's beyond what's usually considered as "high school". – Robert Israel Sep 10 '12 at 20:20