I need to move an object based on 100 images rotating. The object needs to move in a path that is forming an ellipse when I'm rotating the image based on my gestures.

I have 4 points, 2 pairs of opposite points on X/Y axis, on the ellipse but how do I calculate the rest of the points in code-behind so that I can calculate the new X/Y Value of my next/previous point?

Currently I'm just rotating my object in a circle what is a start but not what I want at all...

enter image description here

  • Are the points you have opposite of each other on the ellipse? That is, do you have the points at the ends of both of the axes of the ellipse? – Kris Harper Mar 7 '12 at 12:03
  • So the ellipse will always have its center at [0,0]? Will your 4 points always be like [a,0], [-a,0], [0,b], [0,-b]? – svick Mar 7 '12 at 12:05
  • Yes it will. It's not at [0,0] but I have those coordinates and my points are indeed at the ends of both the axes and are each others opposite. – Tom Kerkhove Mar 7 '12 at 12:08

If you work in polar coordinates, the equation for an eclipse is

enter image description here

(Courtesy of Wikipedia)

a and b are the scaling factors in the X and Y axis, Theta is the angle of rotation.

Translating to your situation, a and b correspond to the points where your ellipse crosses the X and Y axii.

This gives you the radial point at a certain angle of rotation. You can then solve for x and y using Trigonometry.

  • Hm not sure how polar coordinates work but I'll look into it, thx! – Tom Kerkhove Mar 7 '12 at 12:17
  • can you give me some more information about the scaling factors? Are those the difference between my points? For example a = X2 - X1 and b = Y2 - Y1? – Tom Kerkhove Mar 7 '12 at 14:09
  • 1
    Hi. a is the distance from the origin (the point of rotation) to R when the angle of rotation is 0 degrees, similarly b is the distance from the Origin to R when the angle of rotation is 90 degrees. They give the radius of the major and minor axii of the ellipse. – mcfinnigan Mar 7 '12 at 14:32

If your points are always at the ends of the ellipse axes, then your equation should look something like

1 = (x - (x1 + x2)/2)^2 / ((x1 - x2)/2)^2 + (y - (y3 + y4)/2)^2 / ((y3 - y4)/2)^2

Basically, the equation of an ellipse is

(x - x0)^2/a^2 + (y - y0)^2/b^2 = 1

where (x0, y0) is the center of the ellipse and 2a and 2b are the lengths of the horizontal and vertical axes.

So if (x1, y1) and (x2, y2) are the ends of the horizontal axis, then (x1 + x2)/2 is the x-coordinate of the center of the ellipse. Also abs(x1 - x2)/2 is the value of a.

Similarly, if (x3, y3) and (x4, y4) are the ends of the vertical axis, then the same calculations with the y-coordinates give you the y-coordinate of the center and the value of b.

  • I have the centerpointcoordinates so I just need to use (x - x0)^2/a^2 + (y - y0)^2/b^2 = 1? – Tom Kerkhove Mar 7 '12 at 12:24
  • 1
    @HellScream That's the equation of an ellipse. See, e.g. here a little down the page. – Kris Harper Mar 7 '12 at 13:31

Rotation on an elliptical path means that you will want to calculate the Cartesian coordinates (x,y) while time(t) varies. This is dead simple. If P is the period of revolution:

x = a * cos(2 * pi * t / P)
y = b * sin(2 * pi * t / P)

Sorry, no fancy mathematical typesetting. [If someone can point me to a convenient way to do that, that would be great]

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.