Fitting en ellipse to data and finding the vertices

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


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.


If you have $A,B,C,D,E,F$ then you could take the implicit derivative of the equation of the ellipse. As the outer edges would have the critical vales of the derivative.

the implicit derivative is $$-y'(2Cy+Bx+E)=2Ax+D+By$$

and has critical values when either $y'= 0$ or $y'=\pm \infty$ so when $2Ax+D+By=0$ or when $2Cy+Bx+E=0$

The maximum values of x can be found by substituting $2Cy+Bx+E=0$ which is equal to $x=-\frac{2Cy+E}{B}$, into the initial function of the ellipse, and the solving using the quadratic formula.

Similarly you can get maximum values of y by solving $2Ax+D+By=0$ which equals $y=-\frac{2AX+D}{B}$ and again solve by substituting into the initial function of the ellipse, and the solving using the quadratic formula.

hopefully the helps (and makes sense)