Finding intersections of ellipses or spheroids is a fairly complicated task which typically involves solving a quartic equation with an iterative solver. However, the story is very different if the ellipses/spheroids share a focal point. We show below that the problem of finding the intersections reduces to the solution of a 4-by-4 (for spheroids) or a 3-by-3 (for ellipses) linear system. No iterative solver is needed. Also Matlab / Octave code for the solver and plenty of examples are given.
Let us begin with a couple of pictures of ellipses with a shared focal point. The intersections are shown as black stars and the shared focal point as a black circle.
We describe the theory below only for spheroids. Ellipses are just 2D special cases of spheroids. Exactly same equations hold for ellipses by dropping the Z-coodinates.
Without loss of generality, we can assume that the shared focal point lies at the origin.
Assume we have
Let us denote the distance from
By definition of the spheroid, the diameter of the
Now expand the squares and subtract the first equation from the others. This gives a system of
But this is a system of
If
If there are only 3 spheroids, meaning that the matrix on the left in equation (3) has only 3 rows, we can append a row of 4 zeros at the bottom to make it a 4-by-4 matrix. Likewise, we append a zero to the end of the vector on the right.
Let's denote the matrix on the left-hand side of (3) by
If matrix
The matrix can have a full rank only if there are 4 spheroids intersect at one point only. Otherwise, the matrix will be rank deficient. We examine the solutions of the rank deficient cases below.
Let's split matrix
If
Let's continue with spheroids. If the rank is 3, there are 4 ways the column vectors
Assume that the zero is at the first element of the diagonal, so
In this case we can forget column
This can be done with Matlab solver like so:
But the first equation in (1) implies that
Assume that the zero is at the second element of the diagonal, so
As it happens, we can solve it simply as
Now denote
Recall from (1) that
This is a 2nd order polynomial of
Assume that the zero is at the third element of the diagonal, so
We can solve
Using
Now denote
Then solve the 4-by-3 linear system
Recall from (1) that
This is a 2nd order polynomial of
Assume that the zero is at the fourth element of the diagonal, so
This means that
We can solve
Using
Now denote
Then solve the 4-by-3 linear system
Recall from (1) that
This is a 2nd order polynomial of
Note: in every case 1...4 above, it is possible that the zeros of the 2nd order polynomials are complex numbers. If this is the case, the ellipses / spheroids do not intersect. This can happen for example if they are concentric.
The solver can be found in file solveEllipseIntersections.m. The same solver works for both ellipses and spheroids. If the input coordinate vectors have 2 elements, the solver works in 2D mode solving intersections of ellipses. If they have 3 elements, it works in 3D mode for spheroids.
The prototype of the function is
function [intersectionPoints, relativeModelError] = solveEllipseIntersections(sharedFocalPoint, otherFocalPoints, diameters)
Inputs
-
sharedFocalPoint
$~$ Coordinate of the focal point shared by all ellipses / spheroids. A$2\times 1$ vector for ellipses or a$3\times 1$ for spheroids. -
otherFocalPoints
$~$ The other$N$ (non-shared) focal points as a$2\times N$ or$3\times N$ matrix. In 2D mode,$N$ must be either 2 or 3. In 3D mode,$N$ must be either 3 or 4. So you can solve intersections of either 2 or 3 ellipses, or 3 or 4 spheroids. -
diameters
$~~$ Diameters of the ellipses / spheroids along the major semiaxes as an$N$ -by-1 vector.
Outputs
-
intersectionPoints
$~$ Coordinates of the points where the$N$ ellipses / spheroids intersect as column vectors. If there are$M$ intersection points, the output is a$2\times M$ or$3\times M$ matrix.$M$ is either 0, 1 or 2. So the matrix is empty if the ellipses or spheroids do not intersect at all. -
relativeModelError
$~$ (optional) Relative difference between the actual squared distance of the calculated intersection point(s) from the shared focal point and the squared distance predicted by the model. In terms of equations,$\epsilon = \sqrt\frac{\vert x^2+y^2+z^2 - w^2 \vert}{x^2+y^2+z^2}$ where$x,y,x$ is the relative position of the intersection point with respect to the shared focal point. If the relative error is 'large', say, bigger than 0.01, there is reason to believe that accuracy of the returned intersection points is not perfect. The reason can for instance be measurement errors in the input diameters.
Here is a example on how to solve intersections of two ellipses.
% Coordinates of the shared focal point as a column vector
sharedFocalPoint = [0 0]';
% The other focal points of two ellipses at (2,0) and (1,1) as column vectors
otherFocalPoints = [2 0; 1 1]';
% Diameters of the ellipses
diameters = [3 4]';
% Calculate intersections
[intersections, relativeModelError] = solveEllipseIntersections(sharedFocalPoint, otherFocalPoints, diameters)
% Show the ellipses
plotEllipses(sharedFocalPoint, otherFocalPoints, diameters, intersections, "Ellipse demo");
The output will be
intersections =
1.5817 2.4183
-1.0306 0.3639
relativeModelError =
2.4961e-08 3.2242e-08
There are scripts which give examples of all four rank deficient cases described in earlier chapters. Matlab and Octave scripts are living in separate folders because the way they produce graphics output is slightly different.
- demo2D_2.m has examples on intersections of 2 ellipses. The pictures generated by this script are 2-ellipses-case-1.png, 2-ellipses-case-2.png and 2-ellipses-case-3.png.
- demo2D_3.m has examples on intersections of 3 ellipses. The pictures generated by this script are 3-ellipses-case-1.png, 3-ellipses-case-2.png and 3-ellipses-case-3.png. The last picture shows the case where there is only one intersection point.
- demo3D_3.m has examples on intersections of 3 spheroids. The pictures generated by this script are 3-spheroids-case-1.png, 3-spheroids-case-2.png, 3-spheroids-case-3.png and 3-spheroids-case-4.png.
- demo3D_4.m has examples on intersections of 4 spheroids. The pictures generated by this script are 4-spheroids-case-1.png, 4-spheroids-case-2.png, 4-spheroids-case-3.png and 4-spheroids-case-4.png. The last picture shows the case where there is only one intersection point.
Assume that the diameters are measured somehow and the measurements contain small errors. In this case it may happen that the ellipses / spheroids do not appear to intersect at the same point. Let's take a look at an example where noise has been added to diameters of three ellipses which otherwise intersect at a single point (like in this picture).
Despite the errors in the diameter lengths, the intersection point given by the solver is still 'near' the true intersection point. However, it is not possible to say exactly how near. All we can say is that the less error there is in the measured diameters, the closer the solution is to the true intersection point. We also know that the more error there is in the measurements, the larger the relative model error output is. But again, the relative model error does not say how far the given solution is from the correct one. All we can say is that the smaller the error output, the better.