Fitting en ellipse to data and finding the vertices

conic sectionsgeometrylinear algebraMATLAB

I'm using the technique described in Direct Least Square Fitting Of Ellipses to fit an ellipse to a data set. This method works very well and I end up with the parameters for the conic formula:

Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0

From here I can calculate the center of the ellipse with
Xc = (BE – 2CD)/(4AC -B^2), etc…as described on Wikipedia

How can I calculate the vertices of the ellipse? The same Wikipedia article describes a method but I don't quite understand it. I'm basically looking for a way to find the bounds of the ellipse (so I can do things like draw an enclosing rectangle around it or something like that)

Here is my fitted ellipse and calculated center.

enter image description here

Best Answer

Given the real parameters $a$, $b$, $c$, $d$, $e$, $f$, the Cartesian equation:

$$ a\,x^2 + b\,x\,y + c\,y^2 + d\,x + e\,y + f = 0 $$

represents a generic conic in the $\left \langle x,\,y \right \rangle$ plane.

In particular, defined the cubic, quadratic and linear invariants:

$$ i \equiv -\frac{1}{2}\det \begin{bmatrix} 2\,a & b & d \\ b & 2\,c & e \\ d & e & 2\,f \\ \end{bmatrix}, \quad \quad j \equiv -\det \begin{bmatrix} 2\,a & b \\ b & 2\,c \\ \end{bmatrix}, \quad \quad k \equiv \text{tr} \begin{bmatrix} 2\,a & b \\ b & 2\,c \\ \end{bmatrix} $$ if: $$ j < 0 \quad \quad \text{and} \quad \quad i\,k > 0 $$ this conic turns out to be a real non-degenerate ellipse.

In this case, a natural parameterization is as follows:

$$ \begin{cases} x = A + B\,\cos u + C\,\sin u \\ y = D + E\,\cos u + F\,\sin u \\ \end{cases} \quad \quad \text{with} \; u \in [0,\,2\,\pi) $$

where is it:

$$ \begin{aligned} & A \equiv \frac{2\,c\,d - b\,e}{j}\,, \quad \quad B \equiv -\frac{2\,\sqrt{c\,i}}{j}\,, \quad \quad C \equiv 0\,, \\ & D \equiv \frac{2\,a\,e - b\,d}{j}\,, \quad \quad E \equiv \frac{b}{j}\,\sqrt{\frac{i}{c}}\,, \quad \quad F \equiv \sqrt{\frac{-i}{c\,j}}\,. \end{aligned} $$

At this point it's necessary to make it clear what we're interested in.


If we were interested in the coordinates of the vertices of this ellipse, they're determined by minimizing and maximizing the distance function between a generic point of the ellipse and the center of the ellipse, i.e.

  • if $b = 0$, the two pairs of vertices are identified by the following angles: $$ \begin{aligned} & u_1 = 0\,, \quad \quad u_2 = \pi\,; \\ & u_3 = \frac{\pi}{2}\,, \quad \quad u_4 = \frac{3\,\pi}{2}\,; \end{aligned} $$

  • if $b \ne 0$, the two pairs of vertices are identified by the following angles: $$ \begin{aligned} & u_1 = \arctan(z^+)\,, \quad \quad u_2 = \arctan(z^+) + \pi\,; \\ & u_3 = \arctan(z^-) + \pi\,, \quad \quad u_4 = \arctan(z^-) + 2\,\pi\,; \end{aligned} $$

where is it:

$$ z^{\pm} \equiv \frac{-\left(B^2-C^2+E^2-F^2\right) \pm \sqrt{\left(B^2-C^2+E^2-F^2\right)^2 + 4\,\left(B\,C + E\,F\right)^2}}{2\left(B\,C + E\,F\right)}\,. $$


Instead, if we were interested in the coordinates of the extreme points of this ellipse, they're determined by minimizing and maximizing respectively the abscissa and the ordinate of a generic point of the ellipse, i.e. $$ u_1 = 0\,, \quad \quad u_2 = \pi\,; \quad \quad u_3 = 2\arctan(z^+)\,, \quad \quad u_4 = 2\arctan(z^-) + 2\,\pi\,; $$

where is it:

$$ z^{\pm} \equiv \frac{-E \pm \sqrt{E^2 + F^2}}{F}\,. $$


I wish you a good study.