Published: 2013-07-01 | Categories: [»] Tutorials, [»] Physicsand[»] 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-Life2 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-Life2 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

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.

Point Kinematics

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 ROXYZ 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 P1 and P2 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 ROXYZ referential and seen from a second referential RO'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 ROXYZ to referential RO'X'Y'Z'. Assuming a matrix M=(X Y Z) that changes a coordinate from referential ROXYZ to referential RO'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 RO'X'Y'Z' is the transformed position of P from ROXYZ 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 RO'X'Y'Z':

with

which can be seen as the change of the referential ROXYZ as seen from the referential RO'X'Y'Z'.

The speed of P in RO'X'Y'Z' has therefore a much more complex form than only the transformation of v into RO'X'Y'Z' (Mv term)! This is plain normal, imagine a point P fixed in ROXYZ (v=0) but the referential ROXYZ itself is moving relative to RO'X'Y'Z'. Then, P will appear to be moving from RO'X'Y'Z' even if it is well fixed in ROXYZ. 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 ROXYZ as seen from RO'X'Y'Z'. So maybe ROXYZ doesn't move but RO'X'Y'Z' does! Hopefuly, this change nothing to our equations and (little secret) it is in fact impossible to tell if it's ROXYZ or RO'X'Y'Z' which is moving... all that matter is the relative motion of ROXYZ as seen from RO'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 ROXYZ. It is an apparent speed of P due to the rotating motion of the referential ROXYZ as seen from RO'X'Y'Z'.

We may then rewrite the speed of P in RO'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 RO'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 ROXYZ 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.

Rigid-Body Kinematics

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 ROXYZ and because all the points are fixed in the body, the speed and acceleration of any points in ROXYZ are null:

As a consequence, the speed and acceleration of the various points of the bodies as seen from a referential RO'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 RO'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:

Dynamics

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.

Point Dynamics

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 :)

Rigid-Body Dynamics

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.

Conclusions

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 :)

[⇈] Top of Page

You may also like:

[»] Understanding Quaternion-based Rotations

[»] In-line Absorption and Fluorescence Sensor

[»] Data Communication With a PIC Using RS232

[»] Solving Chemical Equilibria on the Computer

[»] Sine Wave Oscillator with Fewer Op-Amp