force and torque calculation in Runge_kutta

Post Reply
mozi
Posts: 2
Joined: Sat Dec 05, 2009 1:05 pm

force and torque calculation in Runge_kutta

Post by mozi »

Hi there,

I'd like to write a game engine and preparing myself for it now.

I am reading Baraff's Siggraph tutorials (Rigid body simulation I -- unconstrained rigid body dynamics) now, here is my question:

when performing numeric integration of the motion equation using 4th order Runge-Kutta method, the calculation of k1, k2, k3 and k4 requires me to evaluate the force and torque, i.e.

k1 = h * f(y0, t0)
k2 = h * f(y0 + k1/2, t0 + h/2)
k3 = h * f(y0 + k2/2, t0 + h/2)
k4 = h * f(y0 + k3, t0 + h)

where, the motion equation is dy/dt = f(y, t) = (v, 0.5wq, force, torque).

My question is how to calculate the forces and torques for the state variables y0+k1/2, y0+k2/2, and yo+k3 ?

many thanks.
dneckels
Posts: 39
Joined: Mon Oct 12, 2009 6:23 pm

Re: force and torque calculation in Runge_kutta

Post by dneckels »

To be strictly correct, the forces and torques would depend on the intermediate object states, so you would have to go all the way back out and calculate the various contacts, collisions, friction, and all other forces/torques in your problem at with the new intermediate states.

Which, practically, doesn't work. So you could do something like hold your forces and torques constant across all the intermediate computations (use the initial values).

Then you really aren't solving the whole system at fourth order, but at least you will be solving the internal dynamics porition of the equations at fourth order (which will make your gyroscopic stability, for instance, much better).

Its basically a form of operator splitting....
Enki
Posts: 9
Joined: Tue May 06, 2008 8:23 pm

Re: force and torque calculation in Runge_kutta

Post by Enki »

I disagree dneckels. The forces and torques are not changing, or at least not changing enough to be outside the required approximation limits, they will be effectively constant over the whole t-zero to h period, so it isn't a problem to keep them so over the whole duration in the computation itself. This holds as long as your timestep is appropriate, whether fixed at short enough intervals or chosen adaptively with regards to error propagation.

If you have a contact or force change happen before time h -- that is an external influence and a single RK4 step isn't meant to deal with those. We need to determine and resolve that externally generated change, find the new forces, and then begin evaluating from that new set of states.
dneckels
Posts: 39
Joined: Mon Oct 12, 2009 6:23 pm

Re: force and torque calculation in Runge_kutta

Post by dneckels »

Well, I think we're saying partially the same thing: that its ok to keep the forces and torques constant over the time step.
For contact/friction/collision forces its probably ok for another reason: these are generally non smooth forces, so higher order integration won't help anyway: it could actually hurt and introduce oscillations.

In my solver I lower the order to verlet once I have contact/collision forces, but keep the RK4 for bodies on a free trajectory. Found it helped with the gyroscopic stability quite a lot.

cheers
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: force and torque calculation in Runge_kutta

Post by bone »

If you want gyroscopic stability, the best methods are by Samuel R. Buss:

http://euclid.ucsd.edu/~sbuss/ResearchW ... /paper.pdf

He shows that RK4 is actually only 2nd order accurate for rotating rigid bodies, and presents much more accurate and efficient algorithms for doing so.
dneckels
Posts: 39
Joined: Mon Oct 12, 2009 6:23 pm

Re: force and torque calculation in Runge_kutta

Post by dneckels »

Thanks, will look at the paper.
Noticed that even RK2 is enough to provide decent gyroscopic stability, so not suprised RK4 is overkill....
Aperion
Posts: 1
Joined: Mon Jan 04, 2010 8:47 pm

Re: force and torque calculation in Runge_kutta

Post by Aperion »

Lately, I have been dealing with the same question as the OP. What exactly do you mean by keep the forces and torques constant across all intermediate computations? Does this basically mean you'd only be accounting for the change in velocity? This does not sound like it would be more stable than an euler integrator. Am I missing something or is that really the case?
dneckels
Posts: 39
Joined: Mon Oct 12, 2009 6:23 pm

Re: force and torque calculation in Runge_kutta

Post by dneckels »

Agreed, this method is at most first order if your forces are nonzero and depend on the bodies state.
But think of the case, for instance, of free fall. The only force is gravity, which is constant anyway. So the method would still be 4th order.
The extra stability comes from integrating the gyroscopic nonlinearity at higher order (Euler blows up if the object is spinning).
Post Reply