Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
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
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
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
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
add comment

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.

share|improve this answer
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
@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
add comment

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]

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.