Rigid body game physics

part 1 part 2 part 3 part 4 part 5 part 6

Inspired by Hubert Eichner’s articles on game physics I decided to write about rigid body dynamics as well. My motivation is to create a space flight simulator. Hopefully it will be possible to simulate a space ship with landing gear and docking adapter using multiple rigid bodies.

The Newton-Euler equation

Each rigid body has a center with the 3D position c. The orientation of the object can be described using a quaternion q which has four components. The speed of the object is a 3D vector v. Finally the 3D vector ω specifies the current rotational speed of the rigid body.

The time derivatives (indicated by a dot on top of the variable name) of the position and the orientation are (Sauer et al.): latex formula The multiplication is a quaternion multiplication where the rotational speed ω is converted to a quaternion: latex formula

In a given time step Δt the position changes as follows latex formula

The orientation q changes as shown below latex formula Note that ω again is converted to a quaternion.

Given the mass m and the sum of external forces F the speed changes like this latex formula In other words this means latex formula

Finally given the rotated inertia matrix I(t) and the overall torque τ one can determine the change of rotational speed latex formula Or written as a differential equation latex formula

These are the Newton-Euler equations. The “x” is the vector cross product. Note that even if the overall torque τ is zero, the rotation vector still can change over time if the inertial matrix I has different eigenvalues.

The rotated inertia matrix is obtained by converting the quaternion q to a rotation matrix R and using it to rotate I₀: latex formula

The three column vectors of R can be determined by performing quaternion rotations on the unit vectors. latex formula Note that the vectors get converted to quaternion and back implicitely.

According to David Hammen, the Newton-Euler equation can be used unmodified in the world inertial frame.

The Runge-Kutta Method

The different properties of the rigid body can be stacked in a state vector y as follows. latex formula The equations above then can be brought into the following form latex formula Using h=Δt the numerical integration for a time step can be performed using the Runge-Kutta method: latex formula

The Runge-Kutta algorithm can also be formulated using a function which instead of derivatives returns infitesimal changes latex formula

The Runge-Kutta formula then becomes latex formula

Using time-stepping with F=0 and τ=0 one can simulate an object tumbling in space.