[ODE] Gravity setup for solar system simulator

Daniel K. O. danielko.listas at gmail.com
Tue Jan 30 21:02:55 MST 2007

David Taylor escreveu:
> I want to simulate solar systems using gravity to keep the planets 
> circling the star and also affecting spaceships.

For a planet's orbit, you will want to use some hard-coded parametric
function to set the position (i.e. make it translate along an ellipse).
ODE would make the orbit unstable and divergent (the planet will simply
go away), because of the nature of the numerical integrator used. And
the "n-body problem" (for n>2) doesn't have an analytical solution, so
you are bound to either use error-prone (and certainly unstable)
numerical aproximations, or "fake it".

> Does this mean the gravity system for ODE 
> expects to work in a planar environment where there is a "floor" and 
> can't be used for space simulations?
Exactly, as that covers ~90% of "gravity needs" (i.e. "things should
just fall down").

But it's not hard to define a vector field to act over all (or most)
bodies at each time step, to attract them to the planet. Just create,
for every body, a force vector pointing to the desired center of
gravity, with length proportional to the gravity force you want; for
realism, it should be inversely proportional to the distance squared.
But for a more arcade-like experience you may want to tweak the formula.

Daniel K. O.

More information about the ODE mailing list