Convert a rotated ellipse to sheared ellipse

2.6k Views Asked by At

Given an ellipse centred at the origin with major and minor axes and slope of the major axis specified:
rotated ellipse

How can I convert those three parameters into parameters that would express a scaled and sheared ellipse at the origin?
sheared ellipse

What I need is the width and height of the green parallelogram and the slope of the blue line when the red line is lying flat.

I might also be interested in versions with angles rather than slopes. I'm assuming it's easier with slopes but I could be wrong.

(I only have maybe highschool level maths so please excuse my ignorance of proper terminology. The images are not mine, just "close enough" ones I found on the net, the angles should actually match. I hope they are clear enough.)


Proposed rewording by @Blue.

A rotated ellipse can be interpreted as a (horizontally-)sheared ellipse. For instance, "an ellipse with radii $a$ and $b$, transformed by rotation through angle $\theta$" is just as well described as "an ellipse with radii $p$ and $q$, transformed by (horizontal) shear of angle $\phi$".

enter image description hereenter image description here

I want to know how to convert from one set of parameters to the other. That is,

$$\text{Given $a$, $b$, $\theta$, what are $p$, $q$, $\phi$?}$$

  • It may be easier to express the amount of rotation and shear as slopes rather than angles.
  • For the shear, I'm more interested the height of the bounding parallelogram ($q$ in the figure) not the transformed radius ($q^\prime$). (Of course, these are related by $q = q^\prime \sin\phi$.)
3

There are 3 best solutions below

1
On BEST ANSWER

Recall that the standard form of an ellipse centered at the origin is $$\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1,$$ where $a$ is half the length of the horizontal axis and $b$ half the vertical (so we only need $a, b > 0$ and there is no need to specify $a > b$). Upon counterclockwise rotation by an angle $\theta$ about the origin, that is to say, $$(x,y) \to (x \cos \theta - y \sin \theta, x \sin \theta + y \cos \theta),$$ this equation takes the form $$Ax^2 + Bxy + Cy^2 = 1,$$ where $$\begin{align*} A &= \frac{\cos^2 \theta}{a^2} + \frac{\sin^2 \theta}{b^2}, \\ B &= \left(\frac{1}{a^2} - \frac{1}{b^2}\right) \sin 2\theta, \\ C &= \frac{\sin^2 \theta}{a^2} + \frac{\cos^2 \theta}{b^2}. \end{align*}$$

Now it should be obvious that the intersection of the red diameter with the ellipse in your second figure is simply the solution to $Ax^2 = 1,$ i.e. $$x = \pm \frac{1}{\sqrt{A}} = \pm \frac{ab}{\sqrt{a^2 \sin^2 \theta + b^2 \cos^2 \theta}}$$ hence the positive value is also half the length of the red diameter.

The blue diameter in the second figure corresponds to the vertical extrema; e.g., what is the largest possible choice of $y$ satisfying $Ax^2 + Bxy + Cy^2 = 1$ for any valid choice of $x$? Some thought should lead you to conclude that this occurs precisely when the quadratic in $x$ $$Ax^2 + (By)x + (Cy^2 - 1) = 0$$ has a repeated root; i.e., the discriminant $$\Delta = (By)^2 - 4A(Cy^2 - 1) = 0.$$ Thus $$y = \pm \frac{2\sqrt{A}}{\sqrt{4AC - B^2}} = \pm \sqrt{a^2 \sin^2 \theta + b^2 \cos^2 \theta}.$$ and the vertical height of the green parallelogram is twice the positive value. The slope of the blue line (after some calculations) should be $$\frac{a^2 \tan \theta + b^2 \cot \theta}{a^2 - b^2},$$ the proof of which is left as an exercise.

I strongly advise you to verify these calculations as I have not spent the time and effort to do so myself.

1
On

Let the input parameters be $(a, b, \theta)$, which are respectively the length of major and minor axis and the angle of rotation. Of course the first thing is to rotate the ellipse to the "standard" one $$\frac{x^2}{a^2} + \frac{y^2}{b^2}=4.$$

Let the new ellipse touches the green parallelogram at $(\pm p/2, 0)$ and $\pm (q/2m, q/2)$. Here $p$ is the width (length of the red line), $q$ is the height of the bounding parallelogram and $m$ is the slope of the non-horizontal green line.

Indeed we need only to find a $2\times 2$ matrix $A$ so that $$A\begin{bmatrix} a/2 \\ 0\end{bmatrix} =\begin{bmatrix} p/2 \\ 0\end{bmatrix}, \ \ \ A\begin{bmatrix} 0\\ b/2\end{bmatrix} = \begin{bmatrix} q/2m \\ q/2\end{bmatrix}.$$ Then the rectangle bounding the old ellipse will be sent under $A$ to the green parallelogram, and the standard ellipse will be sent to the new one, as suggested in the comment.

It is easy to see that

$$A = \begin{bmatrix} p/a & q/bm \\ 0 & q/b\end{bmatrix}.$$

Thus the $ 2\times 2$ matrix

$$\begin{bmatrix} p/a & q/bm \\ 0 & q/b\end{bmatrix} \begin{bmatrix} \cos\theta & \sin\theta \\-\sin\theta & \cos\theta\end{bmatrix}$$

will send the ellipse given by $(a, b, \theta)$ to the ellipse given by $(p,q,m)$.

0
On

The solution to this is the same as the solution to https://stackoverflow.com/questions/3025519/how-do-i-draw-an-ellipse-with-arbitrary-orientation-pixel-by-pixel/ and was detailed in this paper by Nathan Dinsmore in 2015: https://www.dropbox.com/s/su4bkjepexmwh1w/EllipseTransform.pdf?dl=0 "Converting a Rotated Ellipse to a Sheared Axis-aligned Ellipse" There is a proof of concept implementation at https://g6auc.me.uk/ellipses/index.html

(There is an alternative method that requires three shears rather than one, by Alan Paeth from 1986 described in http://graphicsinterface.org/wp-content/uploads/gi1986-15.pdf "A Fast Algorithm for General Raster Rotation")

Since stackexchange prefers the raw data to links, I'll attempt to insert Dinsmore's paper below. Apologies for not being familiar with MathJax - I'm a programmer, not a mathematician.

Converting a Rotated Ellipse to a Sheared Axis-aligned Ellipse

Nathan Dinsmore

March 1, 2015

Abstract

In computer graphics, it is often faster to apply a shear transformation while rasterizing than to apply an arbitrary rotation. This paper presents a method for converting an ellipse described by semi-major and semi-minor axis lengths and rotation angle into an equivalent axis-aligned ellipse with a shear transformation parallel to the y axis.

We begin with the parametric equation of an axis-aligned ellipse with semi-major axis a and semi-minor axis b:

x' = a cos t
y' = b sin t

Applying the rotation transformation

[ x ]   [ cos φ   −sin φ ] [ x' ]
[   ] = [                ] [    ]
[ y ]   [ sin φ    cos φ ] [ y' ]

yields the parametric equation for the input ellipse, described by semi-major axis length a, semi-minor axis length b , and rotation angle φ:

x = a cos t cos φ   −   b sin t sin φ
y = a cos t sin φ   +   b sin t cos φ

The semi-major axis of the sheared (output) ellipse should be the halfwidth of the rotated ellipse, which is magnitude of the x coordinate of any point where dx'/dt = 0, i.e., at:

−a sin t0 cos φ − b cos t0 sin φ = 0
                  a sin t0 cos φ = −b cos t0 sin φ
                          tan t0 = (−b/a) tan φ
                              t0 = tan^(−1) (−(b/a) tan φ)

This gives us the point:

x0 = a cos t0 cos φ − b sin t0 sin φ
y0 = a cos t0 sin φ + b sin t0 cos φ

Thus the semi-major axis of the sheared ellipse is simply a' = |x0|. Since the determinant of the shear transformation parallel to the y-axis

| 1 0 |
|     | = 1,
| λ 1 |

it is area-preserving; thus we may simply equate the areas of the two ellipses to find b'.

πa'b' = πab

b' = ab/a'

Finally, we can calculate λ from the fact that the rightmost (or leftmost) point of the sheared ellipse must coincide with that of the rotated ellipse.

y0 = y'0 + λx'0
   = 0 + λx0
 λ = y0/x0