# 3D Torque and Angular Momentum

CS 493 Lecture, Dr. Lawlor

Rigid-body rotation is actually quite a bit more complex than translation.

 Linear Translation Rotation Position P    vec3, meters Angular Orientation R (see last lecture)    3 angles in radians, a quaternion, or a matrix Velocity V=dP/dt    vec3, m/s Angular Velocity W = dR/dt    3 rates in radians/sec, a quaternion derivative, a skew matrix or    a vec3, radians/sec Acceleration A=dV/dt    vec3, m/s^2 Angular Acceleration    ... even worse ... Mass m    float, Kg Rotational inertia matrix I    mat3, Kg*m^2 Linear Momentum p=mV    vec3, N*s Angular Momentum L=I W    vec3, Kg*m^2/s Force F=mA=dp/dt    vec3, N Torque T = R x F = dL/dt    vec3, N*m OK! huh?!

The standard trick here is to ignore angular acceleration.  Instead, sum up net torques in 3D, integrate (multiply by dt and sum) to get angular momentum, divide by rotational inertia (or multiply by the inverse inertia matrix) to get angular velocity, and use that to adjust the current angular orientation.  Note that everything's a vec3 until that last step.

If you're using Euler angles, you need to compute your roll rate, pitch rate, and yaw rate from your current roll, pitch, and yaw and intended angular velocity.  This takes a whole lot of trig (yuk!).

If you're using a quaternion, evidently you can add in a scaled copy of the quaternion derivative:
`  0.5 * make_quaternion_axis_angle(W,0.0) * normalize(cur_quaternion)`
This comes from the quaternion differentiation formula.

If you're using a rotation matrix, you can add in a scaled copy of this "skew matrix", which is just the time derivative of the per-axis rotation matrix:
`[ 0     -W.z   W.y ][ W.z    0    -W.x ][ -W.y   W.z   0   ]`
You do need to first rotate the skew matrix by the current rotation, or it will stop working after a quarter turn.  You then need to orthonormalize, or the object will slowly grow in size.  Here's a working example we developed mostly in class (but made to work afterwards!):
Rotation Matrix & Angular Velocity Demo

Here's the collision torque version we finished in class Tuesday:
Collision Torque Demo

(See a more complete discussion of applying angular velocity here.)