Quaternion
Summary
Represents a four-dimensional complex number utilised for 3D spatial rotations.
Definition
Namespace: SDT4.Managed.Core.Math
Assembly: SDT4.Managed.Core.dll
struct Quaternion
Implements:
IVectorSpatial<Single, Single, Quaternion, Quaternion>, ISerializable, IEquatable<Quaternion>
Fields
| Name | Type | Description |
|---|---|---|
public w |
Single | The real or scalar component of the quaternion. |
public x |
Single | The X imaginary vector component of the quaternion. |
public y |
Single | The Y imaginary vector component of the quaternion. |
public z |
Single | The Z imaginary vector component of the quaternion. |
Properties
| Name | Type | Description |
|---|---|---|
public static get; Zero |
Quaternion | Gets a quaternion with all components set to zero. |
public static get; Identity |
Quaternion | Gets the identity quaternion representing no rotation (w: 1, x: 0, y: 0, z: 0). |
public get; IsNormalized |
Boolean | Gets a value indicating whether this quaternion is normalised to unit length within tolerance. |
Methods
public static Quaternion RotateAround(Quaternion q, Vector3f axis, Single angle)
Summary: Rotates an existing quaternion around a specified axis by an angle in radians.
Parameters:
-
q(Quaternion): The base orientation quaternion to rotate. -
axis(Vector3f): The normalised axis of rotation. -
angle(Single): The rotation angle in radians.
Returns:
- Quaternion: The resulting rotated orientation quaternion.
public static Quaternion FromAxisAngle(Vector3f axis, Single angle)
Summary: Creates a rotation quaternion representing a rotation around a specified axis by an angle in radians.
Parameters:
Returns:
- Quaternion: A new rotation quaternion.
public Void CopyToValuePtr(Single* valuePtr)
Summary: Copies the vector values into a scalar value pointer.
Parameters:
valuePtr(Single*): Destination value pointer. Must be large enough to contain the values.
public Single LengthSq()
Summary: Calculates the squared length (squared Euclidean norm) of the quaternion.
Returns:
- Single: The squared length.
public Single Length()
Summary: Calculates the length (Euclidean norm) of the quaternion.
Returns:
- Single: The length.
public Quaternion Normalized()
Summary: Returns a normalised copy of this quaternion scaled to unit length.
Returns:
- Quaternion: The normalised quaternion, or Quaternion.Zero if the length is zero.
public Quaternion Conjugate()
Summary: Returns the complex conjugate of this quaternion, negating its vector components (x, y, z).
Returns:
- Quaternion: The conjugate quaternion.
public Quaternion Inverse()
Summary: Calculates the multiplicative inverse of this quaternion.
Returns:
- Quaternion: The inverted quaternion.
public static Quaternion FromRotationMatrix(Matrix3x3f m)
Summary: Constructs an orientation quaternion from a 3x3 orthonormal rotation matrix.
Parameters:
m(Matrix3x3f): The 3x3 rotation matrix.
Returns:
- Quaternion: The corresponding unit quaternion.
public EulerAngle ToEulerAngle(EulerOrder order)
Summary: Converts this quaternion into intrinsic Euler angles according to the specified rotation sequence.
Parameters:
order(EulerOrder): The desired sequence of axis rotations. Defaults to EulerAngle.DefaultOrder.
Returns:
- EulerAngle: An EulerAngle structure representing the orientation.
public Matrix3x3f ToRotationMatrix()
Summary: Converts this quaternion into an equivalent 3x3 orthonormal rotation matrix.
Returns:
- Matrix3x3f: A 3x3 rotation matrix representing the same orientation.
public virtual String ToString()
Summary: Returns a string representation of the quaternion.
Returns:
- String: A formatted string displaying the quaternion components.
public virtual Boolean Equals(Object? obj)
Summary: Determines whether the specified object is a Quaternion and is equal to the current instance.
Parameters:
obj(Object?): The object to compare with this instance.
Returns:
- Boolean:
if the object is a Quaternion and matches all components; otherwise, .
public Boolean Equals(Quaternion other)
Summary: Determines whether the specified Quaternion is equal to the current instance.
Parameters:
other(Quaternion): The quaternion to compare with this instance.
Returns:
- Boolean:
if all corresponding components are equal; otherwise, .
public virtual Int32 GetHashCode()
Summary: Returns the hash code for this quaternion.
Returns:
- Int32: A 32-bit signed integer hash code.
public Void GetObjectData(SerializationInfo info, StreamingContext context)
Summary: Populates a SerializationInfo with the data needed to serialise the quaternion.
Parameters:
-
info(SerializationInfo): The SerializationInfo to populate with data. -
context(StreamingContext): The destination for this serialisation.
public static Single DistanceSq(Quaternion a, Quaternion b)
Summary: Calculates the squared Euclidean distance between two quaternions in 4D component space.
Parameters:
-
a(Quaternion): The first quaternion. -
b(Quaternion): The second quaternion.
Returns:
- Single: The squared Euclidean distance.
public static Single Distance(Quaternion a, Quaternion b)
Summary: Calculates the Euclidean distance between two quaternions in 4D component space.
Parameters:
-
a(Quaternion): The first quaternion. -
b(Quaternion): The second quaternion.
Returns:
- Single: The Euclidean distance.
public static Single Dot(Quaternion a, Quaternion b)
Summary: Calculates the dot product of two quaternions.
Parameters:
-
a(Quaternion): The first quaternion operand. -
b(Quaternion): The second quaternion operand.
Returns:
- Single: The scalar dot product.
public static Quaternion FromEulerAngle(EulerAngle euler)
Summary: Creates a rotation quaternion from an intrinsic EulerAngle according to its specified rotation order.
Parameters:
euler(EulerAngle): The Euler angle angles and axis sequence.
Returns:
- Quaternion: A rotation quaternion representing the combined rotations.
public static EulerAngle ToEulerAngle(Quaternion quat, EulerOrder order)
Summary: Decomposes an orientation quaternion into intrinsic Euler angles according to the specified axis rotation sequence.
Parameters:
-
quat(Quaternion): The orientation quaternion to decompose. -
order(EulerOrder): The desired sequence of axis rotations. Defaults to EulerAngle.DefaultOrder.
Returns:
- EulerAngle: An EulerAngle instance containing pitch, yaw, and roll angles in radians.
public static Quaternion Nlerp(Quaternion a, Quaternion b, Single t)
Summary: Performs a normalised linear interpolation between two quaternions.
Parameters:
-
a(Quaternion): The starting orientation quaternion. -
b(Quaternion): The destination orientation quaternion. -
t(Single): The interpolation factor, where 0 representsaand 1 representsb.
Returns:
- Quaternion: The normalised interpolated quaternion.
public static Quaternion Slerp(Quaternion a, Quaternion b, Single t)
Summary: Performs spherical linear interpolation between two quaternions, maintaining constant angular velocity along the shortest arc.
Parameters:
-
a(Quaternion): The starting orientation quaternion. -
b(Quaternion): The destination orientation quaternion. -
t(Single): The interpolation factor, where 0 representsaand 1 representsb.
Returns:
- Quaternion: The spherically interpolated quaternion.
public static Quaternion LookAt(Vector3f eye, Vector3f target)
Summary: Creates a rotation quaternion that points from an eye position towards a target position, assuming a default up direction of (0, 1, 0).
Parameters:
Returns:
- Quaternion: A rotation quaternion facing the target.
public static Quaternion LookAt(Vector3f origin, Vector3f target, Vector3f up)
Summary: Creates a rotation quaternion that points from an origin position towards a target position with a specified upwards reference direction.
Parameters:
-
origin(Vector3f): The source position vector. -
target(Vector3f): The target point to look towards. -
up(Vector3f): The upwards reference direction.
Returns:
- Quaternion: A rotation quaternion facing the target.
public static Matrix3x3f ToRotationMatrix(Quaternion q)
Summary: Converts a rotation quaternion into an equivalent 3x3 orthonormal rotation matrix.
Parameters:
q(Quaternion): The unit orientation quaternion to convert.
Returns:
- Matrix3x3f: A 3x3 rotation matrix representing the same orientation.
public static Vector3f RotateVector(Quaternion quat, Vector3f vec)
Summary: Rotates a 3D vector by an orientation quaternion.
Parameters:
-
quat(Quaternion): The rotation quaternion to apply. -
vec(Vector3f): The vector to rotate.
Returns:
- Vector3f: The rotated vector.
public static Vector3f RotateVector(Vector3f vec, Quaternion quat)
Summary: Rotates a 3D vector by the inverse of an orientation quaternion.
Parameters:
-
vec(Vector3f): The vector to rotate. -
quat(Quaternion): The rotation quaternion whose inverse will be applied.
Returns:
- Vector3f: The unrotated or inversely rotated vector.
public static Quaternion RotateTowards(Quaternion a, Quaternion b, Single maxDelta)
Summary: Rotates an orientation quaternion towards a target orientation by an angular step not exceeding a maximum delta.
Parameters:
-
a(Quaternion): The starting orientation quaternion. -
b(Quaternion): The destination orientation quaternion. -
maxDelta(Single): The maximum angular step permitted during rotation.
Returns:
- Quaternion: The resulting orientation quaternion rotated towards
b.