Writing a physics engine (Part 2.3: Mass matrix and contact Jacobian)


Intro

We’re going to cover how to find the “mass matrix” and contact Jacobian for rigid bodies (without articulation).

Some of the following may seem obvious or too straight-forward, but in my opinion it’s important to understand the case for non-articulated bodies before moving onto articulated bodies. It’ll be helpful to see the corresponding equations between articulated/non-articulated bodies. We’re also getting ahead of ourselves here, but knowing how to derive these quantities will help us understand the motivation for things like Plücker coordinates we’ll learn about later.


What is a mass matrix?

From high school or introductory mechanics, you may recall the equations for momentum and kinetic energy for a point particle with mass \(m\) and velocity \(\mathbf v\). For momentum, we had \(\mathbf p = m \mathbf v\) and kinetic energy \(T_{\text{trans}} = \frac{1}{2} m v^2\).

You were probably then introduced to rigid bodies rotating in 2 dimensions, you were probably then introduced to the moment of inertia \(I\) and \(T_{\text{rot}} = \frac{1}{2} I \omega^2\).

-

Moving to a 3D rigid object, the rotational term will appear now as a quadratic form:

\[T = \frac{1}{2}mv^2 + \frac{1}{2}{\mathbf \omega_\text{body}}^T I {\mathbf \omega_\text{body}}\]

where \(I\) is positive definite (clearly, since we take kinetic energy non-zero). Here, \(\omega_\text{body}\) is the angular velocity, defined in the frame of the rotating body. That is, \(\omega_\text{world} = R \omega_\text{body}\) and \(\omega_\text{body} = R^T \omega_\text{world}\) .

-

Note that we can rewrite the kinetic energy as one quadratic form:

\[T = \frac{1}{2}\dot{q}^T M \dot{q}\]

where \(\dot{q} = \begin{bmatrix} \mathbf v\ \mathbf \omega_\text{world} \end{bmatrix}^T\). Here, \(M\) is our mass matrix, defined as:

\[M = \begin{bmatrix} m \mathbb 1_{3x3} & \mathbf 0_{3x3} \\ \mathbf 0_{3x3} & RIR^T \end{bmatrix}\]

Note that \(RIR^T\) is simply the moment of inertia in the world frame. For rigid bodies, the mass matrix is super simple. The important properties to recognize:

  1. \(M\) depends on our definition of \(\dot q\). For non-articulated rigid bodies, it makes sense to define \(\dot{q} = \begin{bmatrix} \mathbf v\ \mathbf \omega_\text{world} \end{bmatrix}^T\) (particularly when we consider relative velocities between multiple objects). However, imagine we instead want to define it as: \(\dot{q} = \begin{bmatrix} \mathbf v\ \mathbf \omega_\text{body} \end{bmatrix}^T\). Then we would instead replace the \(RIR^T\) in \(M\) with \(I\).
  2. \(M\) maps from our “generalized velocities” \(\dot q\) to generalized momentum with \(M\dot q\)
  3. \(M\) maps from our “generalized velocities” \(\dot q\) to kinetic energy \(\frac{1}{2}\dot{q}^T M \dot{q}\).

For those unfamiliar with Lagrangian mechanics, the term “generalized” is not well-defined here, it’ll make more sense when we look at articulated bodies.


What is a Jacobian?

This is under construction