Move the sliders. Each time the curve on the right crosses the dashed line, a point appears on the
left.
The ellipse
An ellipse with centre , semi-axes and , turned by an angle , is the
set of points where
and are the coordinates of the point in the ellipse’s own axes.
From two unknowns to one
A point on both ellipses satisfies both equations. Instead of solving for and together,
write any point of the first ellipse with one angle :
where is the rotation by . Put this point into the second ellipse’s equation:
is negative inside the second ellipse and positive outside. Expanding it gives
The coefficients come from three vectors. is the centre of the first ellipse in the second
ellipse’s axes: and at , divided by and . With
:
- and
- and
A polynomial of degree 4
Write . Then and ,
and multiplying by gives
A polynomial of degree 4 has at most four real roots, so two ellipses cross in at most four points.
can’t reach , so if that point is an intersection, . To avoid this, choose
where starts so that the point at is clearly inside or outside the second ellipse.
Solving the quartic
Divide by to get . Ferrari’s idea is to split it
into two quadratics:
Matching the coefficients gives ,
, and
. With , these reduce to a cubic:
Cardano’s formula solves it. With it becomes , where
If ,
and if , the three real roots are
Any real gives the two quadratics:
with the signs paired so that . Each quadratic gives two
roots . Every real one is an intersection: , and the
first equation of this page gives the point .
Two details matter on a computer. When one of the two square roots is close to zero, rounding makes it
inaccurate, so I take only the other one and get the remaining pair from
. And when the cubic has three real roots, I keep the one
that satisfies the four matching equations best.
A double root is a point where the ellipses touch without crossing. If , , and
are all zero, doesn’t depend on : it’s the same ellipse twice if , and
no common point otherwise.
Example
For “Four points” in the demo, the first ellipse has centre , , ,
, and the second has centre , , ,
. The quartic is
The root of the cubic splits it into
The four roots are , , and , so , ,
and . They give the four points , ,
and .
I checked the solver against a separate method with much higher precision, on thousands of cases,
including ellipses that touch and very thin ones. Both always gave the same points.