Maths - Calculus

By: Nobody/Anonymous - nobody
file Runge-Kutta integration?  
2005-06-17 03:26

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 way.  
 
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? 
 
Thanks, 
 
Tom 
 
 
*The modified version can cope with the old "constant linear acceleration over 100 metres" problem. I think it's sometimes called Heun's method.

By: Martin Baker - martinbakerProject Admin
file RE: Runge-Kutta integration?  
2005-06-18 01:42

Tom, 
 
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 necessary. 
 
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. 
 
Martin

By: Nobody/Anonymous - nobody
file RE: Runge-Kutta integration?  
2005-06-19 00:14

Hi, 
 
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 integrator! 
 
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). 
 
Tom


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

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.

cover 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).

Other Math Books

Commercial Software Shop

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.

cover Mathmatica

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.