Compute semi-axes and rotation of a ellipse which has a 2d matrix transform

84 Views Asked by At

A unit circle with a matrix transform becomes a ellipse.

The matrix is present as svg matrix format [a, b, c, d, e, f].

How to compute the semi-axes lengths and rotation of the ellipse?

Fox example:

svg code

<circle cx="0" cy="0" r="1"
 transform="matrix(0.85743718,-0.51458866,0,1,15,22.46)" />

$$ \begin{bmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \\ \end{bmatrix} = \begin{bmatrix} 0.85743718 & 0 & 15 \\ -0.51458866 & 1 & 22.46 \\ 0 & 0 & 1 \\ \end{bmatrix} $$

unit circle to ellipse

SVG Transform Matrix

a transformation matrix

1

There are 1 best solutions below

0
On BEST ANSWER

The circle is given by

$ r^T Q_0 r = 1 $

where $ Q_0 = \begin{bmatrix} 1 && 0 && 0 \\0 && 1 && 0 \\ 0 && 0 && -1 \end{bmatrix} $

and $ r = [x, y, 1]^T $

Now let

$A =\begin{bmatrix} 0.85743718 && 0 && 15 \\ -0.51458866 && 1 && 22.46 \\ 0 && 0 && 1 \end{bmatrix}$

And as requested by the problem

$ r = A r' $

where $r' = [x', y', 1] $

Substitute $r$ into the equation of the circle, then

$ r'^T A^T Q_0 A r' = 0 $

which is of the form

$ r'^T Q r' = 0 $

where $Q = A^T Q_0 A $

Direct evaluation of $Q$ gives us

$ Q = \begin{bmatrix} 1 && -0.51458866 && 1.303896396 \\ -0.51458866 && 1 && 22.46 \\ 1.3038963986 && 22.46 && 728.4516 \end{bmatrix} $

Since $r' = [x', y', 1] $, then the above equation becomes

$ p^T Q_1 p + p^T b + c = 0 $

where $p = [x', y'] $ and

$ Q_1 = \begin{bmatrix} 1 && -0.51458866 \\ -0.51458866 && 1 \end{bmatrix} $

$ b = \begin{bmatrix} 2.607792793 \\ 44.92 \end{bmatrix} $

$ c = 728.4516 $

The first thing to do is find the center of the ellipse. This is given by

$ p_0 = - \dfrac{1}{2} Q_1^{-1} b = \begin{bmatrix} -17.49399297 \\ -31.4622104 \end{bmatrix} $

Now the above ellipse equation becomes

$ (p - p_0)^T Q_1 (p - p_0) = - c + p_0^T Q_1 p_0 = 1 $

Now diagonalize $Q_1$, by computing the angle

$\phi = \dfrac{1}{2} \tan^{-1} \bigg( \dfrac { 2 Q_{1(1,2)} }{ Q_{1(1,1)} - Q_{1(2,2) }} \bigg) = \dfrac{\pi}{4} $

We're going to write $Q_1 = R D R^T $, where

$ R = \begin{bmatrix} \cos(\phi) && - \sin(\phi) \\ \sin(\phi) && \cos(\phi) \end{bmatrix} = \dfrac{1}{\sqrt{2}} \begin{bmatrix} 1 && -1 \\ 1 && 1 \end{bmatrix} $

The diagonal entries of diagonal matrix are given by

$ D_{11} = \dfrac{1}{2} \bigg(Q_{11} + Q_{22} \bigg) + \dfrac{1}{2} \bigg( Q_{11} - Q_{22} \bigg) \cos(2\phi) + Q_{12} \sin(2 \phi) $

$ D_{22} = \dfrac{1}{2} \bigg(Q_{11} + Q_{22} \bigg) - \dfrac{1}{2} \bigg( Q_{11} - Q_{22} \bigg) \cos(2\phi) - Q_{12} \sin(2 \phi) $

Plugging the various entries of $Q_1$ into the above two formulas, gives

$D_{11} = 1/2 (2) + (-0.51458866) = 0.48541134 $

$D_{22} = 1/2 (2) - (-0.51458866) = 1.51458866 $

This means that the semi-major axis length is

$ a = \bigg(\dfrac{1}{\sqrt{D_{11}}} \bigg) = 1.4353077 $

and the semi-minor axis length is

$ b = \bigg( \dfrac{1}{\sqrt{D_{22}}} \bigg) = 0.81255477 $

Rotation of the ellipse major axis from the horizontal position is $\phi = \dfrac{\pi}{4}$