Search code examples
androidgeometrygame-physics

Calculating points of a circle dynamically in an Android game


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


Solution

  • 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)