Struct QuaternionF
An immutable single-precision quaternion used for 3-D orientation representation in body-segment kinematics.
Implements
Inherited Members
Namespace: MOSAIC.Components.BodyRig
Assembly: MOSAIC.dll
Syntax
public readonly struct QuaternionF : IEquatable<QuaternionF>
Remarks
Convention: Hamilton product with layout (X, Y, Z, W) where W is the
scalar (real) component and (X, Y, Z) is the vector (imaginary) part.
Consider replacing with Quaternion if you do not need the custom Euler decomposition or operator overloads defined here.
Constructors
QuaternionF(float, float, float, float)
Initialises a new quaternion with the specified components.
Declaration
public QuaternionF(float x, float y, float z, float w)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | Imaginary X. |
| float | y | Imaginary Y. |
| float | z | Imaginary Z. |
| float | w | Scalar W. |
Fields
Identity
The identity quaternion (0, 0, 0, 1).
Declaration
public static readonly QuaternionF Identity
Field Value
| Type | Description |
|---|---|
| QuaternionF |
Properties
W
Scalar (real) W component.
Declaration
public float W { get; }
Property Value
| Type | Description |
|---|---|
| float |
X
Imaginary X component.
Declaration
public float X { get; }
Property Value
| Type | Description |
|---|---|
| float |
Y
Imaginary Y component.
Declaration
public float Y { get; }
Property Value
| Type | Description |
|---|---|
| float |
Z
Imaginary Z component.
Declaration
public float Z { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Conjugate()
Returns the conjugate (-X, -Y, -Z, W).
Declaration
public QuaternionF Conjugate()
Returns
| Type | Description |
|---|---|
| QuaternionF |
Equals(QuaternionF)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(QuaternionF other)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | other | An object to compare with this object. |
Returns
| Type | Description |
|---|---|
| bool | true if the current object is equal to the |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
FromEulerDegrees(Vector3F)
Creates a quaternion from Euler angles stored in a Vector3F (degrees).
Declaration
public static QuaternionF FromEulerDegrees(Vector3F angles)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3F | angles | Euler angles as |
Returns
| Type | Description |
|---|---|
| QuaternionF |
FromEulerDegrees(float, float, float)
Creates a quaternion from Euler angles in degrees.
Intrinsic Z-Y-X (aerospace) order: yaw (Z), then pitch (Y), then roll (X),
i.e. q = q_z(yaw) · q_y(pitch) · q_x(roll).
Declaration
public static QuaternionF FromEulerDegrees(float rollDeg, float pitchDeg, float yawDeg)
Parameters
| Type | Name | Description |
|---|---|---|
| float | rollDeg | Rotation about X in degrees. |
| float | pitchDeg | Rotation about Y in degrees. |
| float | yawDeg | Rotation about Z in degrees. |
Returns
| Type | Description |
|---|---|
| QuaternionF | A unit quaternion representing the combined rotation. |
Remarks
This is the exact inverse of ToEulerAngles(): for any angles that avoid
gimbal lock, FromEulerDegrees(r, p, y).ToEulerAngles() returns (r, p, y)
in radians. The argument order therefore matches ToEulerAngles()'s
(roll, pitch, yaw) result order.
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
Magnitude()
Returns the magnitude (L2 norm) of this quaternion.
Declaration
public float Magnitude()
Returns
| Type | Description |
|---|---|
| float |
Normalize(QuaternionF)
Returns the unit-length normalised copy (static convenience).
Declaration
public static QuaternionF Normalize(QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| QuaternionF |
Normalized()
Returns a unit-length quaternion in the same direction, or Identity if this quaternion has (near-)zero magnitude.
Declaration
public QuaternionF Normalized()
Returns
| Type | Description |
|---|---|
| QuaternionF |
Pitch(QuaternionF)
Extracts the pitch angle (rotation about the Y axis) in radians. Clamped to ±π/2 to avoid NaN from Asin(float).
Declaration
public static float Pitch(QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| float |
Roll(QuaternionF)
Extracts the roll angle (rotation about the X axis) in radians.
Declaration
public static float Roll(QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| float |
ToEulerAngles()
Decomposes the quaternion into Euler angles (roll, pitch, yaw) in radians, using the intrinsic Z-Y-X (aerospace) convention. Inverse of FromEulerDegrees(float, float, float) (which takes degrees).
Declaration
public Vector3F ToEulerAngles()
Returns
| Type | Description |
|---|---|
| Vector3F | A Vector3F with |
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The fully qualified type name. |
Overrides
Yaw(QuaternionF)
Extracts the yaw angle (rotation about the Z axis) in radians.
Declaration
public static float Yaw(QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| float |
Operators
operator +(QuaternionF, QuaternionF)
Component-wise addition.
Declaration
public static QuaternionF operator +(QuaternionF a, QuaternionF b)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | a | |
| QuaternionF | b |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator /(QuaternionF, float)
Scalar division.
Declaration
public static QuaternionF operator /(QuaternionF q, float s)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q | |
| float | s |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator ==(QuaternionF, QuaternionF)
Equality operator.
Declaration
public static bool operator ==(QuaternionF a, QuaternionF b)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | a | |
| QuaternionF | b |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(QuaternionF, QuaternionF)
Inequality operator.
Declaration
public static bool operator !=(QuaternionF a, QuaternionF b)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | a | |
| QuaternionF | b |
Returns
| Type | Description |
|---|---|
| bool |
operator *(QuaternionF, QuaternionF)
Hamilton quaternion product.
Declaration
public static QuaternionF operator *(QuaternionF a, QuaternionF b)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | a | |
| QuaternionF | b |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator *(QuaternionF, Vector3F)
Rotates a 3-D vector by this quaternion: q * v * q⁻¹.
Declaration
public static Vector3F operator *(QuaternionF q, Vector3F v)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q | The rotation quaternion (should be unit length). |
| Vector3F | v | The vector to rotate. |
Returns
| Type | Description |
|---|---|
| Vector3F | The rotated vector. |
operator *(QuaternionF, float)
Scalar multiplication.
Declaration
public static QuaternionF operator *(QuaternionF q, float s)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q | |
| float | s |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator *(float, QuaternionF)
Scalar multiplication (scalar on the left).
Declaration
public static QuaternionF operator *(float s, QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| float | s | |
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator -(QuaternionF, QuaternionF)
Component-wise subtraction.
Declaration
public static QuaternionF operator -(QuaternionF a, QuaternionF b)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | a | |
| QuaternionF | b |
Returns
| Type | Description |
|---|---|
| QuaternionF |
operator -(QuaternionF)
Negates all four components.
Declaration
public static QuaternionF operator -(QuaternionF q)
Parameters
| Type | Name | Description |
|---|---|---|
| QuaternionF | q |
Returns
| Type | Description |
|---|---|
| QuaternionF |