diff --git a/VpSharp/src/Rotation.cs b/VpSharp/src/Rotation.cs index ca756f6..c27c051 100644 --- a/VpSharp/src/Rotation.cs +++ b/VpSharp/src/Rotation.cs @@ -172,6 +172,24 @@ public readonly struct Rotation : IEquatable, IFormattable return HashCode.Combine(Angle, Roll, Tilt, Yaw); } + /// + /// Converts this rotation to a quaternion. + /// + /// An instance of representing the same rotation as this instance. + public Quaternion ToQuaternion() + { + if (double.IsPositiveInfinity(Angle)) + { + var yaw = (float)Yaw.DegreesToRadians(); + var tilt = (float)Tilt.DegreesToRadians(); + var roll = (float)Roll.DegreesToRadians(); + return Quaternion.CreateFromYawPitchRoll(yaw, tilt, roll); + } + + var axis = new Vector3d(Tilt, Yaw, Roll); + return Quaternion.CreateFromAxisAngle((Vector3)axis, (float)Angle); + } + /// /// Returns the string representation of these coordinates. ///