public static void ToAxisAngle(this __type__ r, ref __v3t__ axis, ref __ftype__ angleInRadians) { angleInRadians = 2 * Fun.Acos(r.W); var s = Fun.Sqrt(1 - r.W * r.W); // assuming quaternion normalised then w is less than 1, so term always positive. if (s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt // if s close to zero then direction of axis not important axis.X = r.X; // if it is important that axis is normalised then replace with x=1; y=z=0; axis.Y = r.Y; axis.Z = r.Z; } else { axis.X = r.X / s; // normalise axis axis.Y = r.Y / s; axis.Z = r.Z / s; } }