# Calculating the angular momentum of rigidbody in Unity3D

Knowing that angular momentum in 3D is L = Iω (moment of inertia times angular velocity), how do I calculate it in video game world?

In I have the diagonal inertia tensor rigidbody.inertiaTensor and I know the angular velocity rigidbody.angularVelocity am I correct when I calculate it like this?

Vector3 angularMomentum = new Vector3(
rigidbody.inertiaTensor.x * rigidbody.angularVelocity.x,
rigidbody.inertiaTensor.y * rigidbody.angularVelocity.y,
rigidbody.inertiaTensor.z * rigidbody.angularVelocity.z
);


Though, that leaves out the property rigidbody.inertiaTensorRotation which makes me think that this is not correct. What actually led me to the other question: In Unity3D, what is the relation between inertiaTensor and inertiaTensorRotation?

That's correct. In a few cases, you will want to take into account the rigidbody.inertiaTensorRotation. It defines the rotation of the moment of inertia. However, in most cases, this is just going to be the identity quaternion.

• Ah, so basically there simply are no products of inertia, as all we have in Unity3D are the principal moments - the diagonal of the tensor? – joltmode May 17 '16 at 19:50
• Wouldn't the product of inertia be calculated using the center of mass and the moment of inertia? It's been awhile since physics for me. – MichaelHouse May 17 '16 at 22:35

It seems to me that what you're doing has the correct basic form. But I think rigidbody.inertiaTensorRotation needs to be taken into account, though I'm not 100% positive on this either.

I would argue though, that it must be that rigidbody.inertiaTensor is diagonal with respect to some arbitrary coordinate frame, while rigidbody.angularVelocity is most likely computed with respect to the world axes. In this respect, simply multiplying the two wouldn't be correct. One would need to rotate either rigidbody.inertiaTensor or rigidbody.angularVelocity into a common frame first. Perhaps then, rigidbody.inertiaTensorRotation would take the inertia tensor into the world frame, thus allowing for multiplication with the angular velocity.

That's my thought at least. Does anyone know if my assumption about the angular velocity is correct?

I dug into this some more and have come to the following understanding. I'm open to be corrected though, so if anyone knows more, please chime in. For now though, this is what I think is going on.

rigidbody.inertiaTensor contains the diagonalized elements of the inertia tensor or the principle moments of inertia. These correspond to some internal symmetry of the rigid body and are expressed relative to some set of axes which need not be the same local axes used to describe the body. The rigidbody.inertiaTensorRotation gives you the rotation needed to express the inertia tensor with respect to the body’s local frame. rigidbody.angularVelocity, however, is expressed in world coordinates.

So, in the most general case, we need to apply two rotations to the diagonal inertia tensor in order to find the angular momentum via Unity’s angular velocity vector: rigidbody.inertiaTensorRotaion defines the rotation for the tensor into the body’s local frame, and rigidbody.rotation defines the rotation for that transformed tensor into the world’s frame.

The exact implementation of how to do this may get ugly. I wanted to work within the standard mathematical frame that I have learned: matrices for tensors and rotations as opposed to fiddling with Unity’s quaternions. I wrote up my own class to do this, although Unity has the Matrix4x4 class, which could work. But you’d have to be mindful when working with the extra dimension, as inertia tensors and rotations are most commonly written as 3x3 matrices. The relation between quaternions and rotations can be found readily.

Another note is that you need to make a similarity transformation (had a link to Wolfram Math World here, but apparently I don't have enough reputation point to include it) when rotating the inertia tensor. (I can't figure out writing in latex on this thing, so the following notation will be ugly) You want:

I_new = R*I_old*RT

where I_new is your newly transformed matrix (inertia tensor), R is the rotation matrix corresponding to one of the quaternions, RT is the transposition of that matrix, and I_old is the original inertia tensor that you're transforming.

I hope this can be of use. And again, if anyone knows this to be incorrect, please post and correct me.