# Intersection of two ellipses

I do not have a background in mathematics and geometry, so I will be so thankful if someone please give me a simple way to get the following, as I tried to understand some posts related to this issues, but I couldn't get a clear idea:

Giving two axis parallel ellipses with the parameters of the center of each ellipse $(x_0, y_0)$ for the first ellipse, $(x_1, y_1)$ for the second, and the major and minor radius for each $(h_0, k_0)$ for the first and $(h_1, k_1)$ for the second. My questions are

1. How to know if two ellipses are intersecting?
2. How to calculate the intersection area between the two ellipses?

• Show us at least some work first. Perhaps start with the equations for the two ellipses?
– user2469
Mar 8, 2016 at 17:17
• I am afraid there is no simple way. You will need to find the intersection points between the two ellipses, which involves the resolution of a quartic equation, and combine the areas of elliptic segments. I am not sure you are ready for that.
– user65203
Mar 9, 2016 at 10:14
• If you explain your goal, maybe we can advise a workaround to avoid the frontal assault.
– user65203
Mar 9, 2016 at 10:25
• @YvesDaoust: You can avoid the quartic equation, cubic is enough, but that's still pretty hard, so on the whole I agree with you.
– MvG
Mar 9, 2016 at 10:42
• @MvG: as there can be four roots, this is indeed an algebraic problem of the fourth degree. The quartic equations are solved by factorization, which results in a cubic equation.
– user65203
Mar 9, 2016 at 11:02

Test for intersection:

You can stretch space in one axis so that one of the ellipses is transformed in a circle. Then there is intersection if

• the center of the circle is inside the ellipse, or
• the center is outside but the distance between the point and the ellipse outline is smaller than the radius.

Testing insideness is immediate (plug the coordinates of the center in the implicit equation of the ellipse and check the sign).

Computing the distance is another matter. Let the center of the circle be $(x,y)$ and the ellipse be at the origin (WLOG), with semi-axis $a,b$ (sorry for the change of notation, I can't help it). The squared distance between the given point and an arbitrary point on the ellipse outline is

$$d^2=(a\cos(t)-x)^2+(b\sin(t)-y)^2.$$

The extrema of the distance are achieved when the derivative cancels, i.e.

$$-a\sin(t)(a\cos(t)-x)+b\cos(t)(b\sin(t)-y)=0$$ which can be written

$$\frac{ax}{\cos(t)}-\frac{by}{\sin(t)}=a^2-b^2.$$

This equation can be rationalized by the usual transform

$$\cos(t)=\frac{1-z^2}{1+z^2},\sin(t)=\frac{2z}{1+z^2},$$

giving the quartic equation

$$byz^4 + 2(ax + (a^2-b^2))z^3 + 2(ax -(a^2-b^2)^2)z-by= 0.$$

One of the real roots gives the shortest distance.

You can't hope to find a simple closed formula for this, since there are many different configurations how the two ellipses could intersect.

I'd start by computing the points of intersection. Even if done cleverly, this requires solving a cubic equation, and performing most of the computation using complex numbers. In the end you will have four points of intersection, and can check whether any of them are real.

That will answer your question as to whether the ellipses intersect, if by “ellipse” you mean the curve. If you are referring to the interior, there may still be the situation where one of the ellipses is completely enclosed inside the other. You can detect that case by checking whether both centers are on the same side (i.e. result in the same sign) for one of the quadratic forms.

If you have points of intersection, then you can connect those with lines to cut the intersection between the ellipses apart along those lines. Afterwards you have decomposed the intersection into several pieces, which are either polygons (in fact rectangles in the case of axis-aligned ellipses) or bounded by one line and one ellipse arc. Computing the area of the former is easy. For the latter, you can apply an affine transformation (i.e. a scaling in one of the coordinate directions, in your case of axis-aligned ellipses) to turn this into a circular segment for which the area is easy to compute, and then correct the computed area for the scale factor to get the original area.

To tackle this problem without a background in mathematics or geometry will be very hard, in my opinion. So unless you are really determined to learn all the required tools, I'd suggest you look for alternatives. Perhaps you can work with an approximation? Or perhaps you can let some computer program do the job for you? It depends on where you need this.

The best solution to find if two ellipses are overlapping is this paper.

Basically if $$u^TAu<0$$ and $$u^TBu<0$$ are the equations of two elliptical regions with $$u=(x,y,1)$$ and $$A$$ and $$B$$ are 3x3 matrices.

Then create the cubic equation $$\det(A+zB)=az^3+bz^2+cz+d$$. The discriminant of the cubic is $$\Delta$$.

The condition that two ellipses don't overlap is $$\Delta>0$$ and either $$b>0$$ or $$c>0$$. This is a good test because it doesn't involve having to find any roots.

"Overlapping" includes the case where one ellipse is inside the other but the outlines don't intersect. For intersecting only, it is a bit more complicated. There are a few more very special cases where the ellipses are just touching.

To find the actual intersection points involves solving a quartic equation as the ellipses can intersect in 4 places at once. So it is a long formula and not so simple to right down.