# Making a game physics engine – rigid body kynematics and dynamics

This article is a brief summary of how to write the differential equations of motion for a rigid body. From these, we can use a finite approximation to calculate a rigid body’s pose (position and orientation) and motion (linear and angular velocity) in a game. It is very math heavy, and it is not intended as an explanation of each equation (for that I suggest a very good book on mechanics like Goldstein), but as a brief recap of all the equations needed to derive a physics engine for a game.

### Transport theorem

The transport theorem allows to calculate the derivative of a time-dependent vector quantity in a fixed space, knowing the components in a rotating frame, and vice-versa.

Let’s consider two frames: one is a fixed frame in the world and the other is attached to a rigid body and moves with it. Let’s call the fixed frame and the moving frame . The orientation of with respect to can be expressed with a* rotation matrix* . A rotation matrix can be seen as an operator that rotates points of a space, or as a change of coordinate matrix from the rotated space to the fixed space: in both cases the colums of the matrix are the components of the vectors of the base of the rotated space expressed in the fixed space.

A time-dependent vector quantity has components in both and and they are related by the rotation matrix with the following equation:

We can then calculate the time-derivative of the vector quantity :

with

is a *skew-symmetric* matrix which represents the *angular velocity operator. *Applying this operator to a vector is the same as taking the cross product with it:

substituting this into () we get the *transport theorem*:

If we indicate derivation with respect to time with a dot and denote an absolute derivative (performed in components of the inertial frame) with an “a” subscript and the relative derivative (performed in components of the body’s rotating frame) with a “r” subscript:

we can write the derivative of a time dependent vector with the following vectorial notation:

It is important to note the difference between the space in which the derivation is performed and the space in whose components the derivative is represented. In fact, we can represent the above equation in by left-multiplying by the rotation matrix:

with

and

substituting we obtain:

which is the vectorial equation nn written in .

The transport theorem will be useful when we need to calculate the derivative of the angular momentum of a rotating body.

### Rigid body kynematics

Let’s consider a point of a rigid body , a reference frame attached to the body, with origin , and an (inertial) world fixed frame is with origin : the point’s coordinates in the two frames are related by:

And if we calculate the absolute velocity of the point, since components are constant in

substituting:

as we0ve seen in the preceding section, is the skew-symmetric angular velocity operator:

So if we indicate the absolute (relative to the world/) velocity of and of the origin as and , respectively, we get the *fundamental equation of the kynematics of rigid bodies*:

### Particle systems dynamics

Newton’s second law of dynamics states that a force acting on a material particle causes an acceleration that is inverseli proportional to the particle’s mass. This is true for all particles in the system:

the resulting force acting on a particle is the sum of all internal and external forces: internal forces are exchanged with all other particles of the system, external forces are external to the system:

if we sum for all the particles in the system:

Newton’s third law of dynamics affirms that two particles exchange two equal and opposite forces , so each interaction cancels itself out:

so we get

Let’s now take the moment of each term:

each couple of forces exchanged by two particles is a null torque:

so we obtain

### Conservation of linear momentum

*Linear momentum* of a particle is defined as the mass times its velocity:

summing on all particles in a system we get the total linear momentum:

the derivative of total linear momentum

with

so we get the *conservation law for total linear momentum of a system of particles*

This equation is valid for rigis bodies as well.

### Conservation of angular momentum

The *angular momentum *of a particle with respect to a point is defined as

summing for all particles in a system we get the total angular momentum:

the derivative of total angular momentum:

we obtain *the conservation law for the total angular momentum of a system of particles*:

### Angular momentum for a rigid body

For a rigid body we can express the field of velocity as

if we substitute into the definition of total angular momentum:

the triple cross product can be expressed as

Now, if we project this vectorial equation on the axis of we get

we call , and *moments of inertia* and , and *products of inertia*:

is the *inertia tensor *or *mass matrix* of the body with respect to the point A. We can use the inertia tensor to express the total angular momentum of the body:

what we are interested in is the absolute derivative of the total angular momentum. Remembering the transport theorem above:

I is constant in :

we get

which is the *conservation law of total angular momentum for a rigid body*

if A = = G the equation simplifies:

### Equations of motion for a rigid body

We now have the equations describing the linear and angular motion of a rigid body in space: