8
\$\begingroup\$

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. http://en.wikipedia.org/wiki/Orbit_equation).

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?

\$\endgroup\$
2
  • \$\begingroup\$ It could be done by simulating gravity which is fairly simple (add a force dependent on the mass * sqrt( distance ) and do simple physics) \$\endgroup\$
    – Elva
    Apr 14, 2011 at 13:18
  • 7
    \$\begingroup\$ No don't do simple physics! Orbits are numerically unstable and everything will implode or explode. \$\endgroup\$ Apr 14, 2011 at 14:46

3 Answers 3

4
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks. Looks like I'll have to use the Newton method to solve the second equation. \$\endgroup\$
    – Artefact2
    Apr 15, 2011 at 6:52
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Actually, the animation is from Wikipedia. \$\endgroup\$
    – Artefact2
    Apr 15, 2011 at 6:42
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – Artefact2
    Apr 15, 2011 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .