**[»] Tutorials**,

**[»] Physics**and

**[»] Programming**.

*Last Modified: 2014-07-31*

Ten years ago, when I was only a young ungrad student, me and my friends couldn't wait for the release of Half-Life^{2} and I remember having spent tough nights just before the official launch date. Not only were we excited to play once again the role of Gordon Freeman in a beautifully narrated first-person-shooter, but couldn't we also just wait to test the physics engine that the developers were talking about so much. And the video were impressive at that time! The physics just looked like the real world; it was incredible and magic.

At that time I was also deeply involved in game programming myself and I was wondering if I could reproduce the physics of Half-Life^{2} or, at least, grasp the theory behind it. So when I saw O'Reilly's book "Physics for Game Developers" (by David M. Bourg) I just couldn't resist and bought it immediately. The book itself is great and I strongly recommend it; but something was clearly missing. In fact, today I realize that it is a bit too light on the topic. Don't misunderstand me: this book is great value for sure. But it does not answer the question "why?". Why do the equations take these forms? Where does all that stuff come from? What is the *meaning* of Newtonian mechanics?

On that side, my engineering courses answered a few questions but not that much. Basically, the lessons at university were just teaching the same things that the book was but in a slightly deeper way. Still, it did not reply to many questions I had. Hopefully, with time, I managed to find pieces of answers on various website and online papers. It's not the whole picture yet, but it's already a nice part of it.

In this post, I would like to present you a different way to look at rigid-body dynamics; a way that would have answered most of the questions I had ten years ago. I hope this will help some of you who could be in the same situation I was. The topic is not that complex but it require some length to present; so I will have to be brief and a basic understanding of Newtonian mechanics will surely be welcome. I have decided to split the post into several sections. First we will study the kinematics of point-objects and rigid-bodies. Only then I will talk about the dynamics of rigid bodies.

Kinematics studies the motion of bodies independently of the causes of movements. It is a preliminary step before being able to talk about the dynamics of bodies.

When our object does not have orientation in space and its mass m can be simplified to a single point P, we can rely on a shorten notation known as point kinematics. The question is not if such an object does actually exist (in which case the answer is "almost never") but only if this representation is sufficient to describe a given problem or not. In the case of video games, many objects can be simplified that way. Think about a light bulb, a bullet or a snow flake. All have complex shapes but as long as we are far enough from them, there is no valid reason in implementing that complexity.

We will consider that our point P moves in a referential R_{OXYZ} of axis {__X__,__Y__,__Z__} and centre O. There are many kind of referential but I will consider one here that is orthonormal. That is their axis have unit length and they are perpendicular to each others. The axis system we use in CGI pipeline is an example of such referential. Orthonormal axes translate into the following equations:

When studying the kinematics of the point P, we will describe its trajectory relative to the point O in the axis {__X__,__Y__,__Z__}. I will describe the trajectory __OP__ as a vectorial function depending on time:

The speed of the point P in the referential is given by the distance travelled from two points P_{1} and P_{2} divided by the time taken for that travel:

This is the definition of the *average speed* for the travel. To access the *instantaneous speed*, simply consider very small travels. This corresponds to the definition of the derivative of __r__(t):

which is itself a vectorial function depending on time. In a similar way, we find the instantaneous acceleration of the point P:

So far, so good. This is the same stuff you will find in any book about classical mechanics. That's because I have kept the best part for now.

Imagine we would like to study the motion of P **attached** to its R_{OXYZ} referential and seen from a second referential R_{O'X'Y'Z'} of centre O' and axis {__X'__,__Y'__,__Z'__}. What does it change to the previous equations?

Concerning the position of P we can say that it's the transformed position __r__(t) from referential R_{OXYZ} to referential R_{O'X'Y'Z'}. Assuming a matrix M=(__X__ __Y__ __Z__) that changes a coordinate from referential R_{OXYZ} to referential R_{O'X'Y'Z'} we may write (now omitting the (t) – but remember they are there):

You can see this as a world transform from object space to global space in the context of game development. The position of P in R_{O'X'Y'Z'} is the transformed position of P from R_{OXYZ} plus the distance between the two referential centres. If you have trouble understanding this, simply imagine a translation first (M=identity matrix) and, in a second step, imagine a rotated referential (for example __X__=(0,1,0), __Y__=(0,0,1) and __Z__=(1,0,0)) centred on the second referential.

From this last equation, we can compute the speed of the point P in the referential R_{O'X'Y'Z'}:

with

which can be seen as the change of the referential R_{OXYZ} as seen from the referential R_{O'X'Y'Z'}.

The speed of P in R_{O'X'Y'Z'} has therefore a much more complex form than only the transformation of v into R_{O'X'Y'Z'} (M__v__ term)! This is plain normal, imagine a point P fixed in R_{OXYZ} (__v__=0) but the referential R_{OXYZ} itself is moving relative to R_{O'X'Y'Z'}. Then, P will appear to be moving from R_{O'X'Y'Z'} even if it is well fixed in R_{OXYZ}. The same thing happens, for example, when looking at earth from space. You might be sitting on your chair immobile, but if an alien would be looking at you from his spaceship, you would appear like moving because the earth is moving relative to his spaceship. The important thing here is that we are speaking of the **relative motion** of R_{OXYZ} as seen from R_{O'X'Y'Z'}. So maybe R_{OXYZ} doesn't move but R_{O'X'Y'Z'} does! Hopefuly, this change nothing to our equations and (little secret) it is in fact impossible to tell if it's R_{OXYZ} or R_{O'X'Y'Z'} which is moving... all that matter is the relative motion of R_{OXYZ} as seen from R_{O'X'Y'Z'}.

Anyway, what can we say about that dM/dt term?

Remember the first condition about orthonormal axis:

which gives, after derivation,

and so,

meaning that the derivative of each axis is perpendicular to its own axis because of the scalar product. As a consequence, it is always possible to express the derivative of each axis as a linear combination of the two other axes:

This time we will derivate the second condition about orthonormal axis:

which gives

leading to the following three equalities:

Considering the result of the former condition, this gives

dM/dt can then be written as the product of an antisymetric matrix with the matrix M:

and so the relative speed of P due to referential motion becomes:

An interesting fact is that the product of any antisymetric matrix with a vector can also be written as a cross-product with some vector __ω__ (expand the matrix product and you will see):

and so

we will call this last term the *angular speed* associated to the referential R_{OXYZ}. It is an apparent speed of P due to the rotating motion of the referential R_{OXYZ} as seen from R_{O'X'Y'Z'}.

We may then rewrite the speed of P in R_{O'X'Y'Z'} as:

which you will find in your Newtonian mechanics book except for the matrix product. This is due to how we perceive the coordinates and is also a very good reason to have a look at where the equations come from!

Note that any vectorial quantity __q__ can be computed the same way:

Finally, we may also compute the acceleration of P as seen from R_{O'X'Y'Z'}:

with d__ω__/dt the *angular acceleration*. Have a check at the literature (or Internet) for applications of all the extra terms.

As an illustration, let's study a referential R_{OXYZ} which turns around its __Z__ axis over time:

by derivation of these axes we get:

Using the previous relations:

and from the definition of __ω__:

This might give you some visualization of __ω__ as our result shows that it is perpendicular to the plane of rotation and proportional to the rotation speed. Hence the name *angular speed vector*.

When any of the two hypotheses of the point kinematics is not met any longer, we have to rely on rigid-body kinematics. By rigid, it is meant that all the points of the solid are well fixed and the whole object cannot be deformed. If this assertion is not met, more complex theories have to be used. But that will be for a later post...

Rigid-Body kinematics might look harder than point kinematics but it is actually a simplification of what I have shown previously. I will consider here that the body is centred in O and oriented along the axis system {__X__,__Y__,__Z__}.

By considering the points in the referential R_{OXYZ} and because all the points are fixed in the body, the speed and acceleration of any points in R_{OXYZ} are null:

As a consequence, the speed and acceleration of the various points of the bodies as seen from a referential R_{O'X'Y'Z'} is:

To simplify the writing, and because the cross product is invariant to rotation,

we may write:

or the speed of a point A (now omitting the ‘ for easiness – but don't forget they are there!):

with

You will surely recognize these two equations in your books! If not, it simply means that the speed of any point of the solid is due to the speed of the origin of the object (its "centre" whatever it may means) and the rotation of the body as seen from the upper referential R_{O'X'Y'Z'}. The same understanding can be taken for the acceleration, with an extra term.

Finally, by taking the speed of two points of the solid A and B:

we find the other well known formula telling us that the speed of the points of a solid are linked together:

In the previous section we have studied how to discuss position, speed and acceleration of point and rigid bodies fixed in their own referential and seen from an upper referential but we did not say much about the causes of motion. This is precisely what dynamics is all about.

The point dynamics is based on a fundamental theorem which states that the *linear momentum* of an object can only be modified if some forces are applied to it:

which might look more familiar when we expand the derivate:

and if the mass is kept constant, we find the F=ma well known equation:

To solve a point dynamics problem, all we have to do is to track the various external forces acting on the object:

which should be integrated numerically but that's another problem for another post :)

The rigid-body dynamics is slightly more complex. We may express the speed of any point of the body through its *centre of gravity* G:

where the centre of gravity is defined by:

and the mass:

Computing these values for a given asset is beyond the scope of this article but I will surely come back on this in another post. There are various kind of centre of an object but we will see that choosing the centre of gravity has a lot of advantages for the description of the theorems.

If we apply the linear momentum theorem to the speed of all the points of the body we find (you can see the integral as a very large sum on all the atoms composing the body):

and so the linear momentum of the body is well described by its centre of gravity.

But in the case of rigid bodies, we are also interested in the *angular momentum* which changes the body orientation. If you push the corner of a box, not only will it move linearly (it will slide on the table) but it will also turn slightly, depending on the distance from the centre and the orientation of the push.

Just like we introduced a fundamental theorem for the linear momentum, there is one for the *angular momentum*:

By expanding __v__ we get:

Let's apply the following property of cross products:

so the previous equation becomes:

with __GP__=(x,y,z).

By introducing the *inertia tensor* I,

we may then simplify the angular momentum theorem to:

which is yet another equation of your text book! Except that this time we know where the inertia tensor thing comes from...

There is a clear (and beautiful) relation between the linear and angular momentum theorems. Just as the linear momentum theorem presents the mass as the property to resist to changes in linear motion due to external forces, the angular momentum theorem presents the inertia as the property to resist to changes in orientation due to external torques. These two equations are actually all what we need to implement rigid-body dynamics.

There is still one trick that I would like to talk about and which comes from David M. Bourg's book. We have seen that the inertia tensor depends on the orientation of the body through its definition. This is some sort of problem because we should recompute it every time we need to integrate the angular momentum theorem... Which is computationally inappropriate for a game!

The trick is to use the derivation property I gave earlier:

and to apply it to the theorem:

so we can now use the inertia tensor expressed in the object local coordinates rather than having to recomputed it every time. Actually, we will also require the body to have constant mass such that

such as to get:

To find the new orientation of the body all we have to do is to integrate the quantity

To find the axis and angle value to append to the body orientation at every integration step.

In this post, I have presented the effect of a referential motion on the speed and acceleration of points attached to that referential. I have shown that the angular speed term and angular acceleration terms do come from the derivation of the transformation matrix from one referential to the other. This development allowed me to show you the importance of coordinates meaning (*i.e.*: in which referential are we expressing the vectors) that are often left aside in classical handbooks. This also allows stressing that the notion of angular velocity and angular acceleration are only valid in orthonormal basis since it is at the root of all the computation we have done.

I have then presented the two fundamental theorems of momentum and how the classical formula could be derived from development of these equations using the former equations of speed and referential. This includes the presentation of the origin of the inertia tensor which is often left aside in most handbooks as well. I have then concluded with a small trick to help you solving dynamics problems by expressing the inertia tensor in its local coordinate only.

As you may have realized, the barebone of this article was not to teach kinematics nor dynamics but only to show the origin of the various concepts met in scholar textbooks. I hope this may have relieved you from frustrations you may have had in the past with more "conventional" approaches :)

**You may also like:**

[»] Understanding Quaternion-based Rotations

[»] In-line Absorption and Fluorescence Sensor