Class FixedQuaternionExtensions
- Namespace
- FixedMathSharp
- Assembly
- FixedMathSharp.dll
Provides extension methods for performing operations and comparisons on FixedQuaternion instances, including approximate equality checks and angular velocity calculations.
public static class FixedQuaternionExtensions
- Inheritance
-
FixedQuaternionExtensions
- Inherited Members
Methods
Angle(FixedQuaternion, FixedQuaternion)
Returns the angle in degrees between two rotations a and b.
public static Fixed64 Angle(this FixedQuaternion start, FixedQuaternion end)
Parameters
startFixedQuaternionendFixedQuaternion
Returns
- Fixed64
The angle in degrees between the two rotations.
Dot(FixedQuaternion, FixedQuaternion)
Calculates the dot product of two quaternions.
public static Fixed64 Dot(this FixedQuaternion lhs, FixedQuaternion rhs)
Parameters
lhsFixedQuaternionrhsFixedQuaternion
Returns
- Fixed64
The dot product of the two quaternions.
FuzzyEqual(FixedQuaternion, FixedQuaternion, Fixed64?)
Compares two quaternions for approximate equality, allowing a fractional percentage (defaults to ~1%) difference between components.
public static bool FuzzyEqual(this FixedQuaternion q1, FixedQuaternion q2, Fixed64? percentage = null)
Parameters
q1FixedQuaternionThe current quaternion.
q2FixedQuaternionThe quaternion to compare against.
percentageFixed64?The allowed fractional difference (percentage) for each component.
Returns
- bool
True if the components are within the allowed percentage difference, false otherwise.
FuzzyEqualAbsolute(FixedQuaternion, FixedQuaternion, Fixed64)
Compares two quaternions for approximate equality, allowing a fixed absolute difference between components.
public static bool FuzzyEqualAbsolute(this FixedQuaternion q1, FixedQuaternion q2, Fixed64 allowedDifference)
Parameters
q1FixedQuaternionThe current quaternion.
q2FixedQuaternionThe quaternion to compare against.
allowedDifferenceFixed64The allowed absolute difference between each component.
Returns
- bool
True if the components are within the allowed difference, false otherwise.
Lerp(FixedQuaternion, FixedQuaternion, Fixed64)
Performs a simple linear interpolation between the components of the input quaternions
public static FixedQuaternion Lerp(this FixedQuaternion start, FixedQuaternion end, Fixed64 amount)
Parameters
startFixedQuaternionendFixedQuaternionamountFixed64
Returns
QuaternionLog(FixedQuaternion)
Computes the logarithm of a quaternion, which represents the rotational displacement. This is useful for interpolation and angular velocity calculations.
public static Vector3d QuaternionLog(this FixedQuaternion q)
Parameters
qFixedQuaternionThe quaternion to compute the logarithm of.
Returns
- Vector3d
A Vector3d representing the logarithm of the quaternion (axis-angle representation).
Remarks
The logarithm of a unit quaternion is given by: log(q) = (θ * v̂), where:
- θ = 2 * acos(w) is the rotation angle.
- v̂ = (x, y, z) / ||(x, y, z)|| is the unit vector representing the axis of rotation. If the quaternion is close to identity, the function returns a zero vector to avoid numerical instability.
Slerp(FixedQuaternion, FixedQuaternion, Fixed64)
Calculates the spherical linear interpolation, which results in a smoother and more accurate rotation interpolation
public static FixedQuaternion Slerp(this FixedQuaternion start, FixedQuaternion end, Fixed64 amount)
Parameters
startFixedQuaternionendFixedQuaternionamountFixed64
Returns
ToAngularVelocity(FixedQuaternion, FixedQuaternion, Fixed64)
Computes the angular velocity required to move from previousRotation to currentRotation over a given time step.
public static Vector3d ToAngularVelocity(this FixedQuaternion currentRotation, FixedQuaternion previousRotation, Fixed64 deltaTime)
Parameters
currentRotationFixedQuaternionThe current orientation as a quaternion.
previousRotationFixedQuaternionThe previous orientation as a quaternion.
deltaTimeFixed64The time step over which the rotation occurs.
Returns
- Vector3d
A Vector3d representing the angular velocity (in radians per second).
Remarks
This function calculates the change in rotation over deltaTime and converts it into angular velocity.
- First, it computes the relative rotation:
rotationDelta = currentRotation * previousRotation.Inverse(). - Then, it applies
QuaternionLog(rotationDelta)to extract the axis-angle representation. - Finally, it divides by
deltaTimeto compute the angular velocity.