Representing transformed ellipse

262 Views Asked by At

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.

Please advise.

1

There are 1 best solutions below

3
On

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.