Torque, a vec3, directly affects angular momentum, but the conversion between the vec3 angular momentum (L) and the vec3 angular velocity (W) happens via the 3x3 rotational inertia matrix:

L = I W

This 3x3 inertia matrix consists of 9 scalar values:

[ Ixx Ixy Ixz ]If we set the origin of our coordinate system to the center of mass, Ixz is the mass-weighted integral of x*z inside the object.

[ Iyx Iyy Iyz ]

[ Izx Izy Izz ]

We often want to compute a
property of a volume, like the moment of inertia above, or mass,
when all we have is a boundary representation such as a polygon
mesh. In these cases we often apply the Divergence
Theorem (this is a 3D specialization of Stokes'
Theorem, also known in 2D as Green's
Theorem).

Now to calculate the volume of the mesh, the divergence theorem tells us we can integrate

For instance, to use this to calculate the mass of a cube with one vertex at the origin, and sides w,l, and h, we can ignore four of the six faces since their normal is orthogonal to

Now let's calculate the mass of the volume whose boundary is given by a triangle mesh. Each triangle with vertices A, B, C has this constant unit surface normal:

Because

integral of

If we sum this across each triangle, we indeed get the mass of the volume, including cases where the boundary includes convex and concave features crossing the X axis, and even for cases where the boundary has interior holes. However, this will not calculate a consistent value for a mesh that is not closed, or has self-intersections.

We can compute the centroid in a similar
fashion, using F(P)=1/2 P.x^{2}, and similar formulas
for y and z. However, we must still calculate the
integral of F across the triangle. In class, we got lost
in the details of how to do this via change of variables to
barycentric coordinates. But there is a useful theorem
that states for a quadratic function like F, it is equivalent to
evaluate
the integral at the midpoints of the triangle edges, which
yields a simple evaluation of F=1/24*n.x*((A+B).x^{2}+(B+C).x^{2}+(C+A).x^{2}) for the centroid
in x. (Typically in
math the notation to generalize across the coordinate axis
uses unit coordinate vectors e_{1}, e_{2}, and
e_{3}, in general e_{d}, so we have F(P)=1/2
(P.e_{d})^{2}.)

For the details of one approach
to generalize this calculation to the full inertia matrix, see Mirtich's
1996 paper "Fast and Accurate Computation of Polyhedral Mass
Properties".