3
$\begingroup$

Suppose I have a general ellipse parameterized by a center point $(h, k)$, semimajor axis $a$, semiminor axis $b$, and rotation angle $\theta$. This has the formula in standard form of

$\frac{((x−h)\cos(\theta) + (y−k)\sin(theta))^2}{a^2} + \frac{((x−h)\sin(\theta) + (y−k)\cos(\theta))^2}{b^2} = 1$

Now, I want to apply an affine transformation in homogenous coordinates given by a general transformation matrix

$\left[\matrix{a & b & e\cr c & d & f\cr 0 & 0 & 1}\right]$

How do get to the transformed parameterization of the ellipse in the new coordinate system given by $(h\prime, k\prime)$, $a\prime$, $b\prime$, and $\theta\prime$?

I can algebraically transform that initial representation into general form resulting in

$A = \frac{\cos(\theta)}{a}^2+\frac{\sin(\theta)}{b}^2$

$B = 2\cos(\theta)\sin(\theta)(\frac{1}{a}^2 - \frac{1}{b}^2)$

$C = \frac{\sin(\theta)}{a}^2+\frac{\cos(\theta)}{b}^2$

$D = 2Ah+Bk$

$E = 2Ck+Bh$

$F = Ah^2 + Bhk + Ck^2 - 1$

from whence I can get the equation of the ellipse in matrix form... but I'm not really sure where to go from there, or if that's even the right direction to start in.

I attempted a short-cut calculating the transformed center and vertex points, and then calculating the distance from the transformed vertices to the transformed center to get the semimajor and semiminor axes, and arctangent between one of the transformed vertices and transformed center to get the value for $\theta$, but for some reason that does not appear to produce correct results.

$\endgroup$
5
  • $\begingroup$ Invert the transformation and substitute, or equivalently use $C'=M^{-T}CM^{-1}$. If you want the new axes, &c, I don’t know of any shortcuts—a general affine transformation only preserves conjugacy of diameters. $\endgroup$
    – amd
    Jan 16, 2019 at 22:46
  • $\begingroup$ @amd That's a little too abstract for me to wrap my head around. Invert the transformation--cool, I can do that. But... substitute what, into where? And what does $C$ mean in your equation? If I can get a transformed equation in general or standard form, I can algebra my way back to the preferred parameterization. $\endgroup$ Jan 16, 2019 at 23:43
  • $\begingroup$ Substitute into the equation of the ellipse, just as you might when performing a transformation of any equation. The $C$ in my hint is the matrix of the conic, which from your question a gather you know how to form. $\endgroup$
    – amd
    Jan 17, 2019 at 0:25
  • $\begingroup$ @amd Ah! I see. I was confused because $C$ is also the name for a component of that matrix. So, if I understand correctly, I need to calculate $Q\prime = M^{-T}QM^{-1}$, where $Q = \left[\matrix{A & B/2 & D/2 \cr B/2 & C & E/2 \cr D/2 & E/2 & F}\right]$, and I should end up with $Q\prime = \left[\matrix{A\prime & B\prime/2 & D\prime/2 \cr B\prime/2 & C\prime & E\prime/2 \cr D\prime/2 & E\prime/2 & F\prime}\right]$ And then given those primed coefficient for the general conic equation, I can algebra my way back to the preferred parameterization. Correct? $\endgroup$ Jan 17, 2019 at 1:05
  • 1
    $\begingroup$ That’s correct. The center of the transformed ellipse is easy to recover—it’s just the image of the original center—but the principal axes will require some work. $\endgroup$
    – amd
    Jan 17, 2019 at 1:08

1 Answer 1

2
$\begingroup$

[Transferring the discussion in comments to an answer.]

Under a general affine transformation, the image of the center of an ellipse is the center of the ellipse’s image, so that’s easily computed. Unfortunately, the principal axes aren’t usually mapped to the axes of the image, although their images are conjugate diameters of the resulting ellipse. There are a couple of approaches that you might take to determine the semiaxis lengths and rotation angle of the image.

Writing the general conic equation $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ in matrix form $$\mathbf x^TQ\mathbf x = \begin{bmatrix}x&y&1\end{bmatrix} \begin{bmatrix}A&\frac B2&\frac D2\\\frac B2&C&\frac E2\\\frac D2&\frac E2&F\end{bmatrix} \begin{bmatrix}x\\y\\1\end{bmatrix} =0, \tag1$$ under the point transformation $\mathbf x' = M\mathbf x$ the matrix $Q$ transforms into $M^{-T}QM^{-1}$. (You can easily derive this by substituting for $\mathbf x$ in (1) and rearranging.) So, you could compute this transformation, extract the new coefficients of the conic equation from the result, and then use standard methods and formulas to extract the parameters that you’re interested in.

You can save yourself some work by looking only at the quadratic part of the equation: the shape of the ellipse is only affected by the linear part of the transformation, so you need only focus on the ellipse with equation $${(x\cos\theta+y\sin\theta)^2\over a^2}+{(x\sin\theta-y\cos\theta)^2\over b^2}=1, \tag 2$$ i.e., decompose the affine transformation into the composition of a translation by $(-h,-k)$, a linear transformation, and then another translation. (Note that I’ve corrected the sign error in your original equation.) In matrix form, we have $(x,y)Q(x,y)^T=1$ and the ellipse’s matrix again transforms as $M^{-T}QM^{-1}$, except that now we’re working with $2\times2$ matrices. Apply the transformation and extract the rotation and semiaxis lengths from the resulting coefficients.

One could, with a lot of tedious work or assistance of a symbolic algebra program, work out a general formula for the resulting parameters, but it’s going to be very ugly. If you’re planning to code this, it’s probably best to take it step-by-step instead of trying to transcribe some complex formula.

There are a couple of alternative approaches that might be interesting, though they don’t lead to simple general formulas, either, and might not be any less work than the above. First notice that you can parameterize your original ellipse as $\mathbf c + \mathbf u\cos t + \mathbf v\sin t$, where $\mathbf c = (h,k)$, $\mathbf u = a(\cos\theta,\sin\theta)$ and $\mathbf v=b(-\sin\theta,\cos\theta)$. Focusing again on the linear part of the transformation, the new ellipse is a translate of $\mathbf r(t) = M\mathbf u\cos t+M\mathbf v\sin t$. The tangent to an ellipse at a vertex is orthogonal to the corresponding principal axis, so a way to find these vertices is to solve $\mathbf r(t)\cdot\mathbf r'(t)=0$ for $t$. Unless you ended up with a circle, there will be two pairs of diametrically opposite solutions. The semiaxis lengths are then just the two lengths $\|\mathbf r(t)\|$ and the rotation angle is also easily computed.

Another possible approach takes advantage of the fact that the original ellipse (again after translation back to the origin) is itself obtained from the unit circle by scaling and rotation, so that this ellipse when further transformed is obtained from the unit circle via some composite transformation given by the matrix $M'=MRS$, with $$R = \begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix} \text{ and } S = \begin{bmatrix}a&0\\0&b\end{bmatrix}.$$ The SVD of $M'$ refactors it into the product of a rotation, a diagonal matrix (i.e., scaling along orthogonal directions) and another rotation. The half-axis lengths of the ellipse are therefore given by the central diagonal matrix, and, since the first rotation leaves the unit circle unchanged, the ellipse’s principal axis directions are the columns of the left-hand rotation matrix in the SVD. The rotation angle is easily recovered from them.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.