# Representing transformed ellipse

I am drawing ellipses using SVGs. An ellipse is described by center {x,y}, radiusX and radiusY. To be able to draw every ellipse, I also added rotate angle alpha. (As described here - every ellipse which has 2d transforms applied results, yet again in an ellipse). I easily manged to calculate rx, ry and the points where they meet the ellipse edge. I also calculated the maximums and minimums of the rotated ellipse. Then I am able to describe it with centre, rx,ry and rotation angle. Now the hard part comes when I want to apply horizontal scale on the rotated ellipse. I have:

• the scale that is applied
• the new center position
• the bounding rectangle of the new ellipse
• the positions of the old rx and ry vectors

The problem is that the old rx and ry are no longer perpendicular. The shape has new radii, and is also rotated by different angle.

I don't want to store the initial ellipse, as well as the matrix applied. I need to find the new ellipse's rx, ry and angle.

• Do you want to find the new ellipse's information from the old $rx,ry,\alpha$, and horizontal expansion, or do you also want to use the old and new bounding rectangle information? – Rory Daulton Jan 28 '16 at 17:48
• Why not wrap you ellipse in a SVG "g"-element and apply a transform to the "g" container element? – achille hui Jan 28 '16 at 23:07

The very web site you link to, as well as sites it links to and many other sites, explain how to take the information about an ellipse (such as the center's coordinates, $r_x$ the semi-major axis, $r_y$ the semi-minor axis, and the angle of rotation) and get the general form of the equation for a conic section

$$Ax^2+Bxy+Cy^2+Dx+Ey+F=0$$

where $A,B,C,D,E,F$ are real constants, and $x$ and $y$ are the coordinates of any point on the ellipse. Those sites often also explain how to get from the general equation back to the ellipse's information.

Using those, we can get a strategy for doing what you want. First, from the information you know about the original ellipse, find its general equation (which means finding the constants $A$ through $F$). Second, apply your horizontal expansion to that equation. If your horizontal expansion is done from the origin, replace $x$ in the equation with $mx$ and simplify to find the new constants--this is very easy. If your horizontal expansion is done from the ellipse's center $(x_c,y_c)$, you replace $x$ with $m(x-x_c)+x_c$--this is not much harder. Third, use the new constants to find the desired information about the new ellipse.

This takes some algebra, but it can easily be programmed once the algebra is done. Note that I ignored the bounding rectangles: I do not see how they would be useful in this strategy. Let me know if you need more details.

• I was hoping for a straight up formula that uses old rx, ry, alpha and horizontal expansion (m) to produce the new rx ry and alpha. I will now try to solve the problem using the ellipse formula. – mpeichev Jan 29 '16 at 11:04
• Such formulas are possible, I just have not seen them before. The strategy I outlined should give you the formulas. If you include some more details, I could work up such formulas. In particular, is $r_x$ guaranteed to be not less than $r_y$? And what is the axis for your horizontal expansion: $x=0$, $x=x_c$, or other? – Rory Daulton Jan 29 '16 at 14:13
• Yes, I assume rx > ry. I always use ellipse centre to be in the coordinate axis' centre (0,0) – mpeichev Jan 29 '16 at 15:07