// Returns the angle of a quaternion (see llRot2Axis for the axis) public LSL_Float llRot2Angle(LSL_Rotation rot) { m_host.AddScriptLPS(1); if (Math.Abs(rot.s) > 1) // normalization needed rot.Normalize(); double angle = 2 * Math.Acos(rot.s); if (angle > Math.PI) angle = 2 * Math.PI - angle; return angle; }
/// <summary> /// Returns the axis of rotation for a quaternion /// </summary> /// <returns></returns> /// <param name='rot'></param> public LSL_Vector llRot2Axis(LSL_Rotation rot) { m_host.AddScriptLPS(1); if (Math.Abs(rot.s) > 1) // normalization needed rot.Normalize(); double s = Math.Sqrt(1 - rot.s * rot.s); if (s < 0.001) { return new LSL_Vector(1, 0, 0); } else { double invS = 1.0 / s; if (rot.s < 0) invS = -invS; return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS); } }