I've spent some time messing around with rigid body simulation, from
a computer games/fun perspective. I don't have any problems with the physics,
but I have run into a confusing conceptual problem when it comes to integrating
the present state of an object to get the new state with Runge-Kutta methods.
At present, I use a modified version of Euler's method*. While a lot of
games seem to get away with it, presumably because they have lots of friction
forces, my simulation is space-based, and even moderate angular accelerations
tend to break it.
I would like to replace it with a 4th order Runge-Kutta method, but there's
one fundamental thing I don't understand in RK methods: what if I "don't
know the future"? I mean that to use RK4 I think I need to be able
to write down time-dependent equations for the forces acting on an object.
I can do that for my reaction thrusters (barely), but I also have to model
collisions and impacts. I don't see that I can write these down in this
So, are collisions a problem for RK4, or can I just do the integration
for the continuous forces and add impulses at the end? What's the best
way to handle this?
*The modified version can cope with the old "constant linear acceleration
over 100 metres" problem. I think it's sometimes called Heun's method.
I'm out of my depth again and you know far more about this than me
but I'll try to answer anyway and perhaps someone can correct me if
It seems to me that collisions represent a discontinuity / singularity
in that we assume that an impulse represents an infinite force for
an infinitely short time. It seems to me that Runge-Kutta methods
only apply to continuous functions? I guess one way to do it might
be to integrate up to the collision then apply the step changes then
continue the the integration.
I don't know what the situations is when the thruster is suddenly
switched on, in other words the second differential of position is
a step change? Does Heun's method cope with this, I'll have to find
out about it.
Thanks, Martin. The approach you suggest makes sense. But it seems
that the integrator wasn't the cause of the problems I saw (or at
least, not a major cause).
Instead, small, non-zero cross-terms in my moment of inertia matrices
broke my simplified thruster control law. These small cross-terms
result from computing the moment of inertia matrix numerically; now
I set small cross-terms to zero manually. That seems to have fixed
the problem. I really was convinced for days that it was down to the
I use a half-Euler, half-Heun's method of integration. I integrate
acceleration to velocity using Euler, and then integrate velocity
to position using Heun's method. I expect a step change in acceleration
might throw all of the usual integrator methods. My instinct though
is that this is not a serious problem, because the integrators are
only after the area under the acceleration curve, and take so few
samples that a discontinuity is unlikely to make their estimates more
wrong than they would be anyway for a complicated acceleration curve.
You can see the advantages of a half-Euler/half-Heun's method by setting
up a constant acceleration situation, and comparing the output from
pure Euler's method and the output from Euler/Heun's method to the
position and velocity derived from the famous formulae for motion
under constant acceleration. I was surprised how badly Euler did for
position, but the combination Euler/Heun's was spot on (but it will
not do so well for changing acceleration).
Where I can, I have put links to Amazon for books that are relevant to
the subject, click on the appropriate country flag to get more details
of the book or to buy it from them.
Mathematics for 3D game Programming - Includes introduction to Vectors, Matrices,
Transforms and Trigonometry. (But no euler angles or quaternions). Also includes
ray tracing and some linear & rotational physics also collision detection
(but not collision response).
Where I can, I have put links to Amazon for commercial software, not
directly related to the software project, but related to the subject being
discussed, click on the appropriate country flag to get more details of
the software or to buy it from them.
This site may have errors. Don't use for critical systems.