Calculating the length of the semi-major axis from the general equation of an ellipse

Solution 1:

In this answer to a related question, it is shown that $$ Ax^2+Bxy+Cy^2+Dx+Ey+F=0 $$ is simply a rotated and translated version of $$ \small\left(A{+}C-\sqrt{(A{-}C)^2+B^2}\right)x^2+\left(A{+}C+\sqrt{(A{-}C)^2+B^2}\right)y^2+2\left(F-\frac{AE^2{-}BDE{+}CD^2}{4AC{-}B^2}\right)=0 $$ which says the semi-major axis is $$ \left[\frac{2\left(\frac{AE^2{-}BDE{+}CD^2}{4AC{-}B^2}-F\right)}{\left(A{+}C-\sqrt{(A{-}C)^2+B^2}\right)}\right]^{1/2} $$ and the semi-minor axis is $$ \left[\frac{2\left(\frac{AE^2{-}BDE{+}CD^2}{4AC{-}B^2}-F\right)}{\left(A{+}C+\sqrt{(A{-}C)^2+B^2}\right)}\right]^{1/2} $$

Solution 2:

One strategy is to rotate the coordinate system so the semi-major/minor axes are parallel to the coordinate axis.

To do that, write your equation as $ax^2 + 2bxy + cy^2 + dx + ey = 1$. We can rewrite the first three terms as $(x \ y)A(x \ y)^T$ for the symmetric matrix $A = \left( \begin{matrix} a & b \\ b & c \end{matrix} \right)$. That matrix can be diagonalized and in the new coordinates, call them $(x', y')$, we have

$$fx'^2 + gy'^2 + hx' + jy' = 1$$

That equation you can now write in a 'standard form' for an ellipse and hence calculate precisely the length of either the semi-major or -minor axis.


I find that $A = RDR^{-1}$ where $D = diag(0.353482063035, 0.21792640308) = diag(f,g)$. (Using WA, link, with the rotation matrix $R$.)