public static void DifferentiateQuaternion(ref Quaternion orientation, ref Matrix3x3 localInertiaTensorInverse, ref Vector3 angularMomentum, out Quaternion orientationChange)
{
Quaternion normalizedOrientation;
Quaternion.Normalize(ref orientation, out normalizedOrientation);
Matrix3x3 tempRotMat;
Matrix3x3.CreateFromQuaternion(ref normalizedOrientation, out tempRotMat);
Matrix3x3 tempInertiaTensorInverse;
Matrix3x3.MultiplyTransposed(ref tempRotMat, ref localInertiaTensorInverse, out tempInertiaTensorInverse);
Matrix3x3.Multiply(ref tempInertiaTensorInverse, ref tempRotMat, out tempInertiaTensorInverse);
Vector3 halfspin;
Matrix3x3.Transform(ref angularMomentum, ref tempInertiaTensorInverse, out halfspin);
Vector3.Multiply(ref halfspin, .5f, out halfspin);
var halfspinQuaternion = new Quaternion(halfspin.X, halfspin.Y, halfspin.Z, 0);
Quaternion.Multiply(ref halfspinQuaternion, ref normalizedOrientation, out orientationChange);
}