views:

52

answers:

2

Hi there

If my X co-ordinates increment every time a frame is drawn, what formula can I employ from the math library in order to have the Y co-ordinate moving around the circumference of a circle frame by frame, creating the illusion of an orbiting object around a continuously moving central point?

I have seen it may involve sin or cos but am not sure how to adjust the variables accordingly per frame.

Many thanks for your help

+1  A: 

You can't make a complete circle if your X coordinate increments every time, because half the time your X coordinate has to be decrementing.

What you want is polar coordinates: theta for angle and r for radius. Your r will remain constant, and your theta will increment continuously. Then your x and y are:

x = r * cos(theta)
y = r * sin(theta)
Ned Batchelder
Many thanks for taking the time to answer my question. Applying mathematics in a game environment makes the whole topic much more interesting, they should use this when teaching kids!
Greenhouse Gases
Working beautifully now thanks to this formula.
Greenhouse Gases
A: 

let ox,oy be the origin of your circle, and px,py be a point on the edge of the circle, with a radius of r

given: (px-ox)^2 + (py-oy)^2 = r^2 definition of circle

solve for py:

(py-oy)^2 = r^2 - (px-ox)^2

(py-oy) = sqrt(r^2 - (px-ox)^2)

py = sqrt(r^2 - (px-ox)^2) + oy <---

So as you increment px with your frames, you can find the appropriate py by recalculating the above formula.

glowcoder
Thanks very much. I think in order to keep the game as smooth as possible I will calculate the points for each frame and store them in an array that can just be read at an index that is incremented upon each loop.To make this calculate dynamically I will recalculate these values if the surfaceChanged method is called.Thank you very much for your help
Greenhouse Gases