[ODE] Gravity

Martin C. Martin martin at metahuman.org
Fri Jan 17 07:10:02 2003


> > Keep in mind though, that energy won't be conserved, so the planets will
> > slowly spiral in toward the stars.
> 
> Energy not conserved?  Can you elaborate?

In one time step, ODE (and all other physics engines) compute an
approximation to the next state of the world.  So, the velocities and
positions will have small errors.  This means that pretty much any
quantity that you think should be conserved (like energy, momentum, center
of mass) will change slowly over time.  ODE's integrator tends to err on
the side of less energy rather than more, so the velocities will slowly go
down over time.  Now that I think about it, that may only be during
collisions, so maybe your planets would spiral out rather than in.  But
either way, don't expect quantities to be exactly conserved over long
periods of time.

A higher order integrator can reduce the error but not eliminate it.  One
thing you can do is compute the energy before the timestep, then again at
the end of the timestep, and adjust the resulting velocities to make them
equal.  Same with any other property that you might want conserved.

Keep in mind that preserving momentum and center of mass are easier than
preserving energy, so maybe ODE conserves those.  (All you need is "equal
and opposite reactions," which may or may not be a property of the
solver.)

- Martin