Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a space-simulation related game, and I am having some trouble implementing the movement of binary stars, like this:

Binary star

The two stars orbit their centroid, and their trajectories are ellipses.

I basically know how to determine the angular velocity at any position, but not the angular velocity over time. So, for a given angle, I can very easily compute the stars position (cf.

I'd want to get the stars position over time. The parametric equations of the ellipse works but doesn't give the correct speed : { X(t) = a×cos(t) ; Y(t) = b×sin(t) }.

Is it possible, and how can it be done?

share|improve this question
It could be done by simulating gravity which is fairly simple (add a force dependent on the mass * sqrt( distance ) and do simple physics) – Kevin van der Velden Apr 14 '11 at 13:18
No don't do simple physics! Orbits are numerically unstable and everything will implode or explode. – LumpN Apr 14 '11 at 14:46
up vote 3 down vote accepted

Following a few links from the Wikipedia page you reference leads to Position as a function of time.

share|improve this answer
Thanks. Looks like I'll have to use the Newton method to solve the second equation. – Artefact2 Apr 15 '11 at 6:52

You seem to have had enough data to produce the handy animation above. Your simulation may need more accuracy than provided by my solution:

For each frame of your animation above, record the pixel positions of the centers of each star. Enter these values into two arrays in your program. For a given time t, find the corresponding four consecutive entries in each array and do a bicubic filter on them to produce the position of each star.

share|improve this answer
Actually, the animation is from Wikipedia. – Artefact2 Apr 15 '11 at 6:42

I've found numerical integration to be the easiest way. The inverse square law (F=GM/r^2) works pretty well. And Runge Kutta order four often called RK4 is easy to implment and works quiet well. You start out by writing a routien which takes first order time derivative, for instance for a single object in 2D space, you have X and Y coordinates, and X and Y velocities. The output is the time derivative, the time derivative of of position is simply velocity, so half of it is just copying values, then the acceleration is just the gravational attraction. Then you follow the Runge Kutta prescription. The error of a single time step is proportional to the time step to the fifth power. You adjust the time step to make the result accurate enough. One advantage on numerical integration is if you want to play with the system to make it more interesting, add extra orbiting bodies, or add friction, or whatever, you alreday have the machinery.

share|improve this answer
Well, yes, this is a solution, but my program is not a physics simulation in real time. It is discrete, and I cannot update everything everywhere. This is why the position as a function of time is nice : doesn't need computation, always exact no matter how frequently the positions are updated. – Artefact2 Apr 15 '11 at 6:52

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.