Game Physics: Motion Dynamics Fundamentals

This post is part of my Game Physics Series.

Before delving deep into the programming aspect of physics engines,  I would like to first go over the fundamentals of motion dynamics. Unless specified otherwise, all discussion is in 3D. Also, when it comes to formula consisting of vectors and matrices, all vectors are considered to be column vectors.

Position & Orientation

Position and orientation of a rigid body are both positional properties. Position is a linear property that defines where the object is located in space, and orientation is an angular property that defines how the object is oriented.

Position is typically represented as a vector, and orientation in 3D can be represented by a 3D vector (the direction is the rotation axis, and the magnitude is the rotation angle), a 3-by-3 matrix (basis vectors as columns), or a quaternion.

I prefer storing a 3-by-3 orientation matrix and, in addition, its inverse. These two matrices are used to transform vectors between world space (global coordinates) and model space (rigid body’s local coordinates), an operation that would be carried out quite frequently within a single time step.

Linear Velocity & Angular Velocity

Linear velocity, denoted v(t), is the rate of change of position, denoted x(t). The position change over a time step is the integration of velocity over time. Using the Euler Method, the formula is as follows:

    \[ x(t + \Delta t) = x(t) + v(t) \Delta t \]

Angular velocity, denoted \omega (t), is the rate of change of orientation, denoted o(t). In 2D, angular velocity is just a scalar, and the change of orientation is very similar to the formula for position change. Again, the following formula uses the Euler Method.

    \[ o(t + \Delta t) = o(t) + \omega (t) \Delta t \]

However, this gets trickier in 3D. In 3D, angular velocity is typically represented as a 3D vector, where its direction is the axis of rotation, and its magnitude is the rotation angle. True, if the representation of choice for orientation is also a 3D vector, then the formula for change of orientation would be the same as the 2D case (as shown above). However, if the orientation is represented as a 3-by-3 matrix, then computing the change of orientation involves first converting the angular velocity vector into a rotation matrix and then prepend that matrix to the orientation matrix.

    \[ o(t + \Delta t) = R(\hat{\omega} (t), |\omega(t)| \, \Delta t) \,\, o(t),  \]

where \hat{\omega}(t) is \omega (t) normalized, |\omega (t)| is the magnitude of \omega (t), and R(\hat{n}, \theta) is the angle-axis rotation matrix with axis \hat{n} and angle \theta.

Force & Torque

When you apply a force, denoted F(t), to a rigid body, it would change its velocity and possibly, depending on the point of force application, its angular velocity.

Each force application corresponds to a resulting torque, denoted \tau (t). If the torque is non-zero, then the angular velocity is changed. Torque is defined as the cross product between the vector from center of mass to the force application point, denoted r(t), and the force vector.

    \[ \tau (t) = r(t) \times F(t) \]

Mass & Moment of Inertia

Mass, denoted m, is a physical property that defines how difficult it is to move an object. The larger the mass, the harder it is to move an object.

Moment of inertia is the angular counterpart of mass that defines how difficult it is to rotate an object along a certain axis. With different rotation axis of choice, the moment of inertia might be different. To fully describe the moment of inertia of an object with respect to any arbitrary axis, we usually use a 3-by-3 matrix called “inertia tensor”, denoted I. The moment of inertia with respect to an arbitrary axis \hat{n} is then:

    \[ I_{\hat{n}} = \hat{n}^T \, I \, \hat{n},  \]

where \hat{n}^T is the transpose of the column vector \hat{n}. You can find a list of inertia tensors of some common primitive shapes here.

For other shapes, the inertia tensor can be calculated using the formula below:

    \[ I =  \int _{V} {\left[ {\begin{array}{ccc}    y^2 + z^2 & -xy & -xz \\    -xy & x^2 + z^2 & -yz \\    -xz & -yz & x^2 + y^2 \\   \end{array} } \right]} \rho \, \mathrm{d}V,  \]

where V is the entire volume of the shape, \mathrm{d}V is the infinitesimal volume within V at (x, y, z), and \rho is the density of \mathrm{d}V. Note that (x, y, z) are the coordinates relative to the reference point of choice.

Linear Momentum & Angular Momentum

Linear momentum, denoted P(t), is a physical property that defines how difficult it is to change an object’s linear motion. Linear momentum is defined as the product between mass and linear velocity.

    \[ P(t) = m \, v(t) \]

Angular momentum, denoted L(t), defines how difficult it is to change an object’s angular motion. Angular momentum is defined as the product between the inertial tensor and angular velocity. Note that this quantity is a 3D vector, as the inertia tensor is a 3-by-3 matrix and the angular velocity is a 3D vector.

    \[ L(t) = I \, \omega(t),  \]

Linear Impulse & Angular Impulse

The integrals of force and torque over time are respectively defined as linear impulse, denoted \Delta P, and angular impulse, denoted \Delta L. Linear impulse is also equal to the change of linear momentum, and angular impulse is also equal to the change of angular momentum, hence the deltas in their notations. Using the Euler Method, we get:

    \[ \Delta P = F(t) \Delta t \]

    \[ \Delta L = \tau (t) \Delta t \]

Applying linear impulse and angular impulse would change the velocity and angular velocity, respectively.

The change of linear velocity due to a linear impulse is the linear impulse divided by mass or, in other words, product between inverse mass and linear impulse.

    \[ \Delta v = m^{-1} \Delta P \]

The change of angular velocity due to an angular impulse is the product between the inverse of inertia tensor and angular impulse. Note that we have to convert the angular impulse to the object’s model space and then convert the change of angular velocity back to world space, since the inertia tensor is computed in the object’s model space.

    \[ \Delta \omega = Q I^{-1} Q^T \Delta L,  \]

where Q is the object’s orientation matrix. Since Q is orthogonal, Q^{-1} is equal to Q^T.

End of Motion Dynamics Fundamentals

That’s it. I have covered the aspects of motion dynamics you’ll need for building a physics engine. I strongly encourage you to get very familiar with these definitions and relationships between properties, so familiar that they become your second instinct. After all, you probably don’t want to be bothered by these fundamentals when you really want to focus on the physics engine.

About Allen Chou

Physics / Graphics / Procedural Animation / Visuals
This entry was posted in Gamedev, Physics. Bookmark the permalink.

2 Responses to Game Physics: Motion Dynamics Fundamentals

  1. Patashu says:

    You use basis vector once but don’t define what a basis vector is.

Leave a Reply to Allen Chou Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.