Solved

Ellipse stretching

Posted on 2004-10-05
31
1,415 Views
Last Modified: 2008-01-09
Hi, hope someone can help with this little geometry problem

I have an ellipse (centered at the origin for simplicity) that I want to scale non-uniformly (along one axis only).
If the stretching is performed along one of the ellipses' own axes the operation is trivial. The length of eiher the major or minor axis will change, while the other axis and the angle will remain the same.

Suppose however I choose to scale/stretch along an axis which is not the major nor the minor axis of the ellipse, say for example an axis that runs at 45 degrees through the origin. The resulting transformation of my ellipse will be a combination of rotation and scaling which leaves the ellipse axes rotated to an angle between the original 0 degrees and the scaling direction of 45. I want to know how this transformation works, i.e. how to derive the new parameters of the ellipse from the old parameters (x,y, a, b, theta) and the scaling direction and magnitude.

An example: start with an ellipse having semimajor axis along x-axis 2units, semiminor axis along the y-axis, 1 unit. Centered on the origin.
Scale by a factor 2 along a line running at 45deg through the origin. (this is tried with a nurbs-cad program so the ellipse is only an approximation of the mathematical ellipse, but the result looks like the result I want).

The resulting ellipse has the following properties (still centered at the origin)

Semimajor axis about 3.3 units long, at an angle of 25.6 degrees from the x-axis.
Semiminor axis is roughly 1.2 units.



Thanks for any pointers


0
Comment
Question by:alkonaut
  • 10
  • 8
  • 7
  • +4
31 Comments
 
LVL 7

Assisted Solution

by:Xxavier
Xxavier earned 150 total points
ID: 12227686
eg For scale by 2 along 45deg line: rotate by -45deg, scale by 2 and then rotate by 45deg
0
 
LVL 27

Expert Comment

by:d-glitch
ID: 12227867
You might do better with polar coordinates.  It gives you access to all the parameters you want.


Your original ellipse is                     r  =  2.0*COS( theta)         +  1.0*SIN( theta)

Your desired ellipse is                     r  = 3.3*COS( theta -25.6)  +  1.2*SIN( theta -25.6)


I don't know what happened to the factor or 2 or the 45 degree angle.
0
 
LVL 13

Assisted Solution

by:SteH
SteH earned 150 total points
ID: 12228043
I think to get a general solution you need to find the points of your original ellipsis using

x = d + a 0   * cos (phi-theta)            phi goes from 0 to 2 pi, a and b and theta as in your Q.
y    e    0 b       sin (phi-theta)            d and e are offsets of the ellipsis from the origin.
            A

To stretch this along a x direction by a factor of c you multiply by the matrix  
c 0 = S
0 1
If the stretching is along a different direction you need to rotate this direction to the x axis first, do the scaling and next rotate back. The rotation is (http://mathworld.wolfram.com/RotationMatrix.html)
 cos(psi)   sin(psi)   = R
-sin(psi)    cos(psi)

Now your equation for calculating the points gets:

x = R^(-1) S R* ( d  + A cos (phi-theta))
y                       ( e        sin  (phi-theta))

With c = 2, a = 2 , b = 1 and theta = 0 this becomes:
x = 0.5 * (3 1 * d   +  6 1   cos (phi-theta))
y             (1 3    e       2 3   sin (phi-theta))


0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12228260
more precisely for my idea

eg For scale by 2 along 45deg line: rotate by 45deg clockwise, scale by 2 in X cordinate and then rotate back by 45deg counterclockwise

( use the form  x=acos(s), y=bsin(s)    0<=s<=2pi for the ellipse )
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12228367
ie multiple the vector by the follwing set of matrices in order

acos(s)
bsin(s)

Multiply by

cos(45)   sin(45)  
-sin(45)   cos(45)

then

2 0
0 1

then

cos(-45)   sin(-45)  
-sin(-45)   cos(-45)
0
 
LVL 22

Expert Comment

by:grg99
ID: 12228996
Are you sure the stretched figure is still an ellipse?    

Sounds mildly unlikely at a first glance.


It would be neat if there was a proof of this.

0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12229149
instinct says I do not think it is an ellipse
0
 
LVL 1

Author Comment

by:alkonaut
ID: 12232350
Thanks for the feedback, I'll try some of the suggestions and get back to you =)

I have a few comments on your suggestions so far

Steh:

>With c = 2, a = 2 , b = 1 and theta = 0 this becomes:
>x = 0.5 * (3 1 * d   +  6 1   cos (phi-theta))
>y             (1 3    e       2 3   sin (phi-theta))

I'm really tired now so this could be easy, but how do I get back my (x,y,a,b,theta)-form from this form?


> eg For scale by 2 along 45deg line: rotate by 45deg clockwise, scale by 2 in X cordinate and then rotate back by 45deg
> counterclockwise

If I have an ellipse, then rotate it by 45 then I'll have to scale a tilted ellipse along the X-axis!! this is the exact same problem as scaling an x-aligned ellipse along a tilted axis!


> Are you sure the stretched figure is still an ellipse?    

Assuming the result is *not* an ellipse, it's sure still an elliptical shape with a strange tilt on the axis. I still need to know what happens to a circle if scaled twice, along two different axes (where the second scaling is not along one of the axis of the ellipse which resulted from the first scale).

I think It's an ellipse thogh, but I cant prove it but I'll try this way: imagine the unit circle, and imagine applying two stretching transformations in sequence to it. The first ellipse is the image of a circle under a linear transformation. The two scalings however could be seen as a single linear transformation (by composition of linear transformations), so the resultant ellipse could also be seen as the image of the unit circle under a linear transformation. Since the image of a circle under a linear transform is an ellipse, the final ellipse should be a real "ellipse", am I right?

My best guess so far is that one needs to construct the characteristic matrix, then do some tricks with the eigenvectors (principal axes), but I'd sure like to see an easier way. I'll try the polar+matrix suggestion by SteH first.

0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12232466
>>If I have an ellipse, then rotate it by 45 then I'll have to scale a tilted ellipse along the X-axis!! this is the exact same problem as scaling an x-aligned ellipse along a tilted axis!<<

No it is not. By scaling along the X axis you are now scaling along the axis that was at 45o to the original ellipse, now you rotate back to the original orientation. To scale along the X axis you merely mutliply the X component of the ellipse by the scale factor.

If this is not it then you had better clarify what you mean by scaling an axis that is not a major axis minor



0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12232477
'major axis minor' shld read 'major or minor axis'
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12232500
this is not a difficult problem and the Maths is well known, to scale any object along a give diriection you rotate the object so that the scale direction is now along the X axis, now scale everything along the X axis (by multiplying the X component by the scale constant) then rotate everthing back.
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12232663
For the ellipse ( 0<= s <=2pi )

x(s) = a*cos(s)
y(s) = b*sin(s)

scaled by K along an axis at angle T to the X axis the equation is by this sequence of matrix mults


|X(s)| =  | cos(-T) sin(-T) |  | K   0 |  | cos(T) sin(T)  |  | a*cos(s) |
|Y(s)|     | -sin(-T) cos(-T)|  | 0   1 |  | -sin(T) cos(T) |  | b*sin(s)  |

ie

X(s) = Kcos(-T)cos(T) a*cos(s) + Kcos(-T)sin(T) b*sin(s)
            -sin(-T)sin(T) a*cos(s) +  sin(-T)cos(T) b*sin(s)

Y(s) = -Ksin(-T)cos(T) a*cos(s) - Ksin(-T)sin(T) b*sin(s)
            -cos(-T)sin(T) a*cos(s) +  cos(-T)cos(T) b*sin(s)

which does not look like an ellipse to me

0
 
LVL 1

Author Comment

by:alkonaut
ID: 12235077
To illustrate what I'm looking for I made a little figure (Now I do it the other way around, stretch a tilted ellipse horizontally, but my point remains the same).

http://62.181.192.140/anders/ellipse.jpg

The smaller ellipse is an ellipse with radii 2 and 1, which is rotated. The two horizontal lines are the bounds of the array on the y-axis. I drew those lines because when I scale along the global x-axis they will also be the bounds of the new ellipse of course.

The larger ellipse results from scaling in the global x-direction by a factor two. If it's not a mathematical ellipse then I don't know what it is. It looks very much like an ellipse, and points placed on the perimeter on the smaller ellipse map to points on the perimeter of the larger ellipse. The axis of the larger ellipse is inclined less than the axis of the smaller, and this tilt will tend to zero as I increase the stretch factor. Supposing the larger shape is not an ellipse, then I'd like to know what ellipse would best describe the shape of it (i.e. the angle will do).

Note that ni the figure both curves are nurbs curves, so in reality neither shape is a mathematical ellipse, but it was the best I could do without access to maple/mathematica/gnuplot or some similar program.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12235356
A scaled/stretched ellipse is still an ellipse.
0
 
LVL 13

Expert Comment

by:SteH
ID: 12235487
Even if stretched not along minor or major axis? This I doubt. That would mean that you can find for any
R_1^(-1) S_1R_1 a rotation R_2 and scaling S_2 so that
R_1^(-1) S_1 R_1 = R_2 S_2.

if you look at the off diagonal elements of the lhs you get
s_x1 * sin (phi_1) and
-s_y1 * sin (phi_1)
and for the rhs:
(s_x2 - s_y2) * sin (phi_2) * cos (phi_2)
for both elements to have the lhs the off diagonal identical you need to have
s_x1 = -s_y1 which limits the possible cases to circles stretched giving ellipsis. That seems obvious.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:alkonaut
ID: 12235493
thanks ozo.

Here's another figure showing the original major axis and the scaled version of that axis which becomes a diameter in the new ellipse, but not the major axis. The major axis in the new ellipse is drawn in green, and it's the angle of this axis I'm looking for.

Some facts that might help:

- the major and minor axis in the original ellipse become conjugate diameters in the new ellipse.
- The tangent points against the horizontal lines move with the scaling like expected and determine the new tangent points for the new ellipse


http://62.181.192.140/anders/ellipse2.jpg

0
 
LVL 1

Author Comment

by:alkonaut
ID: 12235999
Steh: Regardless of wether the result is an ellipse or not, all cad programs (try AutoCad, Rhino3D etc.) scale tilted ellipses along another axis to produce a new ellipse. If I fit a tilted ellipse inside an axis-aligned box so that the ellipse touches all 4 sides, then scale box+and ellipse I will get a new axis aligned box, and the old 4 tangent points will be translated in the x-direction so that the tangent points of the new ellipse in the new box are located at the scaled positions of the old tangent points.

So which ellipse is it that is inscribed in this new box, i.e. what are its axis lengths and angle?

I made yet another figure to illustrate this better. The yellow circles are the tangent points on the box which is aligned to the scaling direction. These tangent points are invariant. The red diameter in the scaled (bottom) ellipse is known, it is the scaled version of the major axis of the first ellipse. The green axis of the bottom ellipse is the sought line. Note that I put the ellipses on top of each other for clarity, but they should have a shared center which is the origin for the scale operation.

http://62.181.192.140/anders/ellipse3.jpg




 
0
 
LVL 13

Expert Comment

by:SteH
ID: 12236249
Should one still open jpeg images? ;-)

But at least I understand now your needs.
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 12236358
Find the transform that stretches a circle into the original ellipse.
Multiply the two stretching transforms.
You now have the transform that stretches a circle into the new ellipse.
0
 
LVL 6

Expert Comment

by:Sergio_Hdez
ID: 12236939
A rotated elipse that is then stretched on the X axis is NOT AN ELIPSE anymore!

Why? Because at start, both axis were ortogonal, but in the end, they are not, so the resulting shape is not a elipse.

Think of it in that way: An elipse can be boxed inside a rectangle. Once rotated the rectangle remains a rectangle (axis are ortogonal) but now you stretch it on x axis and the rectangle converts into a romboid... and the shape inside is NOT an elipse anymore... may be an "elpsoid2 or other name would fit, but not an elipse.

If you want to see this graphically, download visor.exe from http://www.hcsoft.net/hclabwin/archivos.php?haz=descarga&ruta=&file=HCVisor.exe, it is a drawing program of my own, where elipses are drawed using a special kind of splines (made up or elipsoid patches).

Once you have it, click on the pencil and select tool "circle", draw an elipse by click and drag a rectangular shape (this is the rectangular box I mentioned). Select the red arrow in the tools bar, right click on the elipse, and chose "girar" (rotate), and rotate any angle. Now, to stretch it, use right click and select "Agrupar" (group). The new group, that only contains the rotated elipse, can now be streched in x or y axis... once stretched, right clik and "desagrupar" (break the group) so you will see the bounding rectangle converted to an romboid.
0
 
LVL 13

Expert Comment

by:SteH
ID: 12237014
This I found out as well. The problem has changed. Given a rectangular box there is one ellipse fitting just inside. How does its major axis rotate if the bounding box is streched?
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12237555
I have given  the stretching transform above
0
 
LVL 1

Author Comment

by:alkonaut
ID: 12237681
I'll repeat my  argument for the end result being an ellipse, but I don't know if its correct:

The argument is based on this:
"- a circle transformed by a linear transformation produces an ellipse."

Start with the unit circle, then scale along x (yielding an ellipse), rotate (giving us the tilted ellipse) and scale again (to get the resultant 3rd shape).
call the matrices representing these transformations T1, T2, T3.

Now suppose the 3rd shape is NOT an ellipse by the arguments above. Since the 3 transformations are linear I can describe them as a single transformation T, by multiplying the matrices of the individual transformations: T3*T2*T1 = T.

So the resulting shape is the image of the unit circle under the linear transformation T. By the starting argument, this shape must be an ellipse. Can someone back me up on this?



Sergio:
 I'm aware that the axes of the original ellipse don't scale to become the axes of the new ellipse (they become conjugate diameters in the new ellipse actually), but still, there is nothing that says that the axis must scale to the new axes for the ellipse to scale to a new ellipse? (see the ellipse3.jpg figure to see what I mean. There exists a new major axis which is not the image of the old axis under the transformation.).


0
 
LVL 1

Author Comment

by:alkonaut
ID: 12237755
Xavier:

> I have given  the stretching transform above

I surely know how to do composite transforms of points (i.e. creating and multiplying transformation matrices), but I want to do this entirely with the ellipse in the description (x,y,a,b,theta), how do you apply your finished transform to an ellipse described in this way?

I mean I'm sure that If I apply it to the points around the ellipse I'll get the positions of the points around the perimeter of the new ellipse, but I wont get the new (x,y,a,b,theta) description of the new ellipse from this will I?
0
 
LVL 13

Expert Comment

by:SteH
ID: 12238454
To go from a circle to an ellipse the matrix T needs to be of the form
a 0
0 b
The rotation is of the form
cos   -sin
sin     cos
That fixes you on how the resulting matrix will look and how it needs to be. There is a difference.

Another way: rotate one ellipse with a,b as axes and another with s*a, b so that their height is h > 2*b. The coordinate where it will touch the right or left boundary will be different for those two ellipses. (Can try to give numbers if needed). If you rotate the first and stretch by s afterward in x the tangent to the left won't move up or down->Not an ellipse anymore.
0
 
LVL 13

Expert Comment

by:SteH
ID: 12238478
But what is your need? Do you need to find the figure that you get when stretching an ellipse around an axis not parallel to minor nor major axis? Or do you want to find the ellipsis inscribing a rectangle which you are strechting?
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 12239095
"but I wont get the new (x,y,a,b,theta) description of the new ellipse from this will I?"

At the moment I am not convinced that the result is an ellipse. And  as yet I am not convinced either by ozo's last argument, it is not clear that a concatenated sequence of 2 stretch operations along different axis is still a stretching transform. I will check later, it is not hard to prove or disprove (to busy now).
0
 
LVL 13

Expert Comment

by:SteH
ID: 12239324
I must correct myself. It seems that stretched ellipse is still an ellipse!
General equation for an arbitrary ellipse:
F/pi = e = b x^2 + 2a xy + c y^2
From this and
c = (1 + a^2) / b
you can derive the points where the ellipse is touching its bounding rectangle:
sqrt(e*b) , -a sqrt (e/b)
-a sqrt (e/c), sqrt (ec)
The ellipse will go cross x-axis at sqrt (e/c) and y-axis at sqrt (e/b).
When I stretch that ellipse in x by a factor s I get
e' = b' x^2 + 2 a' xy + c' y^2
with
a' = a
b' = s b
c' = c / s
e' = s e
so it is still an ellipse!

Have not yet found how to calculate the new axes and the new angle though.
0
 
LVL 6

Expert Comment

by:Sergio_Hdez
ID: 12248882
I agree with ozo, stretched elipse is an elipse, i was wrong... what is not true is that the stretched axis become the new axis on the new elipse, it is false, so applying same transformations to the axis is of no use.... i keep on thinking... beep!

A grown (but not bad idea at first glance) is this approach:

You have an initial elipse non rotated, now you rotate it alpha radians, and then stretch it on x and y (x multiplied by ex, y by ey, for instance), and you get the new elipse... so new eliupse can be obtained appliying this matrix to the original set of points:

[ex 0]      [cos alpha       0      ]
[0 ey]  X  [    0         -sin alpha]

This matrix product gives the transformation from non rotated original elipse to the final one, but if it is a real elipse, it could have also obtained by first stretching and then rotating, but the scale factor ex and ey are different (call them ax, ay) and the angle alpha now is another sligthly different one beta... so if both transformation are the same one, this matrix product must equal the first one:

[cos beta       0      ]     [ax 0]
[    0         -sin beta] X [0 ay]

Form this equation, new know ex, ey and alpha, and can get ax, ay and beta, that are exactly the 3 params that we need to know the resulting elipse... from here is just a matter of "plain work"... i will do it a little:

It is worng because it is not a point to point equality, but a "set of points" to "set of points", meaning that a given point will not be equaly moved in first and second case, no the method fails... if anyone know how to fix it from here, all for you!
0
 
LVL 13

Expert Comment

by:SteH
ID: 12249010
Hi Sergio Hdez
the general rotation matrix is
[cos alpha    -sin alpha]
[sin alpha     cos alpha]

But i think you need to go from the know points where an ellipse touches a surrounding rectangle. From there calculate angle of the major axis and the axis parameters of the ellipse.

Using the parameters of my last post the relations are
b = B/A sin^2(theta) + A/B cos^2(theta)
a = (A/B - B/A) cos (theta) sin (theta)
c = B/A cos^2(theta) + A/B sin^2(theta)
A and B are major and minor axis of the ellipse and theta its rotation. a, b and c can be calculated from the touching points or the rectangle. So you should be able to solve those equations to get theta, A and B. Unfortunately I currently don't have time nor means to do so. Anyone with mathematica or maple here?
0
 
LVL 1

Author Comment

by:alkonaut
ID: 12253490
I've finally solved it! I don't know if this is the easiest way, but it works.

The first state of the ellipse can be described as a transformation of the unit circle by a stretching followed by a rotation (translations are ignored here). This rotation and stretching is described by matrices R and S respectively (normal scale and rotate matrices, 2x2).

if (x,y) represent all points on the unit circle, then (x',y') are the points on the initial ellipse when

(x', y') = R*S*(x,y)  

To this starting ellipse we may now want to apply another transformation, for example the scaling we've been discussing all along. Suppose we want to transform our ellipse using a transform matrix S2, then the resulting matrix will be

(x'', y'') = S2*R*S*(x,y)  which we can write as T*(x,y) where T is the product of the matrices.

T = S2*R*S
= [a  b]
   [c  d]

The inverse of T has coefficients e,f,g,h, computed from a,b,c,d
T^-1
= [e  f]
   [g  h]

 Now, if we invert the whole equation for the points on the final ellipse

(x,y) = T^1 (x'', y'')  

Here comes the tricky step. Now one recalls the unit circle equation x^2+y^2=1 and writes it using our new variables x'' and y'' giving

(e^2+g^2)x''^2 + 2(ef+gh)x''y'' + (f^2+h^2)y''^2 = 1

or equivalently as a "characteristic matrix" for the ellipse

[e^2+g^2   ef+gh  ] = A
[ef+gh        f2^+h2]

The directions of the axes of the ellipse are the eigenvectors of this matrix (orthogonal, since the matrix is symmetric)
The two eigenvalues give the semimajor and semiminor axis lengths r1 and r2 as

r1= 1/sqrt(lambda1)  
and
r2 = 1/sqrt(lambda2)

(May be a few typo's in this solution here, but I've tested it in code already and it works).

Thanks everyone for all your input! I'll go over all your hints and split the points somehow tomorrow.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now