Distance between two axis-parallel ellipses

euclidean-geometry

I have two axis parallel ellipses. I want to find the gap (minimum distance) between the two.
The ellipses are defined as :

$$\frac{(x-x_1)^2}{a_1^2} + \frac{(y-y_1)^2}{b_1^2} = 1$$
$$\frac{(x-x_2)^2}{a_2^2} + \frac{(y-y_2)^2}{b_2^2} = 1$$

I am not looking for a closed-form equation. I will be using this in a computer program and it is perfectly OK to loop through a set of values and compute the min or max.

My reasoning so far is:

  1. The distance between circles is $|c_1 – c_2| – (r_1 + r_2)$ i.e. the norm of the difference between the two centers subtracted by the sum of the radiuses.
  2. An axis parallel ellipse is a circle scaled on the axis.
  3. But each of the two ellipses would be using a different scale.
  4. I am wondering if we can translate the formula (1) to the ellipse case somehow. The point $c_1$ will be origin going through a transform $T_1$. The point $c_2$ will be the origin transformed by $T_2$. How do we calculate the "distance" between these two points. What can we say about $r_1$ and $r_2$.

Best Answer

You define the ellipses on the Cartesian form : $$\text{Ellipse 1 : }\quad \frac{x-x_1)^2}{a_1^2} + \frac{(y-y_1)^2}{b_1^2} = 1 $$ $$\text{Ellipse 2: }\quad \frac{(X-x_2)^2}{a_2^2} + \frac{(Y-y_2)^2}{b_2^2} = 1$$ But I think that for algoritmic process it is easier to use the equivalent parametric polar form : $$\text{Ellipse 1 :}\begin{cases} x=x_1+\frac{\cos(\theta)}{\sqrt{\frac{\cos^2(\theta)}{a_1^2}+\frac{\sin^2(\theta)}{b_1^2}}}\\ y=y_1+\frac{\sin(\theta)}{\sqrt{\frac{\cos^2(\theta)}{a_1^2}+\frac{\sin^2(\theta)}{b_1^2}}} \end{cases}\quad \text{Ellipse 2 :}\begin{cases} X=x_2+\frac{\cos(\Theta)}{\sqrt{\frac{\cos^2(\Theta)}{a_2^2}+\frac{\sin^2(\Theta)}{b_2^2}}}\\ Y=y_2+\frac{\sin(\Theta)}{\sqrt{\frac{\cos^2(\Theta)}{a_2^2}+\frac{\sin^2(\Theta)}{b_2^2}}} \end{cases}$$ Consider successive values of $\theta_k$ and $\Theta_k$ each varying independently from $0$ to $2\pi$.

Compute the corresponding $(x_k,y_k)$ and $(X_k,Y_k)$ with the above formulas.

Compute the distance between the two points : $$d_k=\sqrt{(X_k-x_k)^2+(Y_k-y_k)^2}$$
So you can find $(d_k)_{minimum}$ which gives an approximate value of the distance between the ellipses.

If the result is close to $0$ this means that the ellipses intersect. This doesn't mean that they are necessarily tangent.