Class QuaternionHelper
- Namespace
- HelixToolkit.Maths
- Assembly
- HelixToolkit.Maths.dll
Represents a four dimensional mathematical quaternion.
public static class QuaternionHelper
- Inheritance
-
QuaternionHelper
- Inherited Members
Fields
Identity
The identity Quaternion (0, 0, 0, 1).
public static readonly Quaternion Identity
Field Value
One
A Quaternion with all of its components set to one.
public static readonly Quaternion One
Field Value
SizeInBytes
The size of the Quaternion type, in bytes.
public static readonly int SizeInBytes
Field Value
Zero
A Quaternion with all of its components set to zero.
public static readonly Quaternion Zero
Field Value
Methods
Angle(Quaternion)
Gets the angle of the quaternion.
public static float Angle(this Quaternion q)
Parameters
Returns
- float
The quaternion's angle.
AngleBetween(in Quaternion, in Quaternion)
Returns the absolute angle in radians between two Quaternion/>
public static float AngleBetween(this in Quaternion source, in Quaternion other)
Parameters
sourceQuaternionThe first Quaternion
otherQuaternionThe second Quaternion
Returns
Axis(Quaternion)
Gets the axis components of the quaternion.
public static Vector3 Axis(this Quaternion q)
Parameters
Returns
- Vector3
The axis components of the quaternion.
Barycentric(Quaternion, Quaternion, Quaternion, float, float)
Returns a Quaternion containing the 4D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.
public static Quaternion Barycentric(Quaternion value1, Quaternion value2, Quaternion value3, float amount1, float amount2)
Parameters
value1QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 1 of the triangle.
value2QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 2 of the triangle.
value3QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).
Returns
- Quaternion
A new Quaternion containing the 4D Cartesian coordinates of the specified point.
Barycentric(ref Quaternion, ref Quaternion, ref Quaternion, float, float, out Quaternion)
Returns a Quaternion containing the 4D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.
public static void Barycentric(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, float amount1, float amount2, out Quaternion result)
Parameters
value1QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 1 of the triangle.
value2QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 2 of the triangle.
value3QuaternionA Quaternion containing the 4D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).resultQuaternionWhen the method completes, contains a new Quaternion containing the 4D Cartesian coordinates of the specified point.
BetweenDirections(ref Vector3, ref Vector3)
Computes a quaternion corresponding to the rotation transforming the vector source to the vector target.
public static Quaternion BetweenDirections(ref Vector3 source, ref Vector3 target)
Parameters
sourceVector3The source vector of the transformation.
targetVector3The target vector of the transformation.
Returns
- Quaternion
The resulting quaternion corresponding to the transformation of the source vector to the target vector.
BillboardLH(Vector3, Vector3, Vector3, Vector3)
Creates a left-handed spherical billboard that rotates around a specified object position.
public static Quaternion BillboardLH(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)
Parameters
objectPositionVector3The position of the object around which the billboard will rotate.
cameraPositionVector3The position of the camera.
cameraUpVectorVector3The up vector of the camera.
cameraForwardVectorVector3The forward vector of the camera.
Returns
- Quaternion
The created billboard quaternion.
BillboardLH(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Quaternion)
Creates a left-handed spherical billboard that rotates around a specified object position.
public static void BillboardLH(ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, ref Vector3 cameraForwardVector, out Quaternion result)
Parameters
objectPositionVector3The position of the object around which the billboard will rotate.
cameraPositionVector3The position of the camera.
cameraUpVectorVector3The up vector of the camera.
cameraForwardVectorVector3The forward vector of the camera.
resultQuaternionWhen the method completes, contains the created billboard quaternion.
BillboardRH(Vector3, Vector3, Vector3, Vector3)
Creates a right-handed spherical billboard that rotates around a specified object position.
public static Quaternion BillboardRH(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)
Parameters
objectPositionVector3The position of the object around which the billboard will rotate.
cameraPositionVector3The position of the camera.
cameraUpVectorVector3The up vector of the camera.
cameraForwardVectorVector3The forward vector of the camera.
Returns
- Quaternion
The created billboard quaternion.
BillboardRH(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Quaternion)
Creates a right-handed spherical billboard that rotates around a specified object position.
public static void BillboardRH(ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, ref Vector3 cameraForwardVector, out Quaternion result)
Parameters
objectPositionVector3The position of the object around which the billboard will rotate.
cameraPositionVector3The position of the camera.
cameraUpVectorVector3The up vector of the camera.
cameraForwardVectorVector3The forward vector of the camera.
resultQuaternionWhen the method completes, contains the created billboard quaternion.
Exponential(Quaternion)
Exponentiates a quaternion.
public static Quaternion Exponential(Quaternion value)
Parameters
valueQuaternionThe quaternion to exponentiate.
Returns
- Quaternion
The exponentiated quaternion.
Exponential(ref Quaternion, out Quaternion)
Exponentiates a quaternion.
public static void Exponential(ref Quaternion value, out Quaternion result)
Parameters
valueQuaternionThe quaternion to exponentiate.
resultQuaternionWhen the method completes, contains the exponentiated quaternion.
Get(Quaternion, int)
Gets or sets the component at the specified index.
public static float Get(this Quaternion q, int index)
Parameters
qQuaternionindexintThe index of the component to access. Use 0 for the X component, 1 for the Y component, 2 for the Z component, and 3 for the W component.
Returns
- float
The value of the X, Y, Z, or W component, depending on the index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the
indexis out of the range [0, 3].
IsNormalized(Quaternion)
Gets a value indicting whether this instance is normalized.
public static bool IsNormalized(this Quaternion q)
Parameters
Returns
Logarithm(Quaternion)
Calculates the natural logarithm of the specified quaternion.
public static Quaternion Logarithm(Quaternion value)
Parameters
valueQuaternionThe quaternion whose logarithm will be calculated.
Returns
- Quaternion
The natural logarithm of the quaternion.
Logarithm(ref Quaternion, out Quaternion)
Calculates the natural logarithm of the specified quaternion.
public static void Logarithm(ref Quaternion value, out Quaternion result)
Parameters
valueQuaternionThe quaternion whose logarithm will be calculated.
resultQuaternionWhen the method completes, contains the natural logarithm of the quaternion.
LookAtLH(Vector3, Vector3, Vector3)
Creates a left-handed, look-at quaternion.
public static Quaternion LookAtLH(Vector3 eye, Vector3 target, Vector3 up)
Parameters
eyeVector3The position of the viewer's eye.
targetVector3The camera look-at target.
upVector3The camera's up vector.
Returns
- Quaternion
The created look-at quaternion.
LookAtLH(ref Vector3, ref Vector3, ref Vector3, out Quaternion)
Creates a left-handed, look-at quaternion.
public static void LookAtLH(ref Vector3 eye, ref Vector3 target, ref Vector3 up, out Quaternion result)
Parameters
eyeVector3The position of the viewer's eye.
targetVector3The camera look-at target.
upVector3The camera's up vector.
resultQuaternionWhen the method completes, contains the created look-at quaternion.
LookAtRH(Vector3, Vector3, Vector3)
Creates a right-handed, look-at quaternion.
public static Quaternion LookAtRH(Vector3 eye, Vector3 target, Vector3 up)
Parameters
eyeVector3The position of the viewer's eye.
targetVector3The camera look-at target.
upVector3The camera's up vector.
Returns
- Quaternion
The created look-at quaternion.
LookAtRH(ref Vector3, ref Vector3, ref Vector3, out Quaternion)
Creates a right-handed, look-at quaternion.
public static void LookAtRH(ref Vector3 eye, ref Vector3 target, ref Vector3 up, out Quaternion result)
Parameters
eyeVector3The position of the viewer's eye.
targetVector3The camera look-at target.
upVector3The camera's up vector.
resultQuaternionWhen the method completes, contains the created look-at quaternion.
Rotate(Quaternion, Vector3)
Rotates a Vector3 by the specified quaternion rotation.
public static Vector3 Rotate(this Quaternion value, Vector3 vector)
Parameters
valueQuaternionThe quaternion.
vectorVector3The vector to rotate.
Returns
- Vector3
A newly Vector3 rotated by the specified quaternion rotation.
Rotate(Quaternion, ref Vector3)
Rotates a Vector3 by the specified quaternion rotation.
public static void Rotate(Quaternion value, ref Vector3 vector)
Parameters
valueQuaternionThe quaternion.
vectorVector3The vector to rotate.
RotationAxis(Vector3, float)
Creates a quaternion given a rotation and an axis.
public static Quaternion RotationAxis(Vector3 axis, float angle)
Parameters
Returns
- Quaternion
The newly created quaternion.
RotationAxis(ref Vector3, float, out Quaternion)
Creates a quaternion given a rotation and an axis.
public static void RotationAxis(ref Vector3 axis, float angle, out Quaternion result)
Parameters
axisVector3The axis of rotation.
anglefloatThe angle of rotation.
resultQuaternionWhen the method completes, contains the newly created quaternion.
RotationLookAtLH(Vector3, Vector3)
Creates a left-handed, look-at quaternion.
public static Quaternion RotationLookAtLH(Vector3 forward, Vector3 up)
Parameters
Returns
- Quaternion
The created look-at quaternion.
RotationLookAtLH(ref Vector3, ref Vector3, out Quaternion)
Creates a left-handed, look-at quaternion.
public static void RotationLookAtLH(ref Vector3 forward, ref Vector3 up, out Quaternion result)
Parameters
forwardVector3The camera's forward direction.
upVector3The camera's up vector.
resultQuaternionWhen the method completes, contains the created look-at quaternion.
RotationLookAtRH(Vector3, Vector3)
Creates a right-handed, look-at quaternion.
public static Quaternion RotationLookAtRH(Vector3 forward, Vector3 up)
Parameters
Returns
- Quaternion
The created look-at quaternion.
RotationLookAtRH(ref Vector3, ref Vector3, out Quaternion)
Creates a right-handed, look-at quaternion.
public static void RotationLookAtRH(ref Vector3 forward, ref Vector3 up, out Quaternion result)
Parameters
forwardVector3The camera's forward direction.
upVector3The camera's up vector.
resultQuaternionWhen the method completes, contains the created look-at quaternion.
RotationMatrix(ref Matrix3x3, out Quaternion)
Creates a quaternion given a rotation matrix.
public static void RotationMatrix(ref Matrix3x3 matrix, out Quaternion result)
Parameters
matrixMatrix3x3The rotation matrix.
resultQuaternionWhen the method completes, contains the newly created quaternion.
RotationMatrix(Matrix4x4)
Creates a quaternion given a rotation matrix.
public static Quaternion RotationMatrix(Matrix4x4 matrix)
Parameters
matrixMatrix4x4The rotation matrix.
Returns
- Quaternion
The newly created quaternion.
RotationMatrix(ref Matrix4x4, out Quaternion)
Creates a quaternion given a rotation matrix.
public static void RotationMatrix(ref Matrix4x4 matrix, out Quaternion result)
Parameters
matrixMatrix4x4The rotation matrix.
resultQuaternionWhen the method completes, contains the newly created quaternion.
RotationYawPitchRoll(float, float, float)
Creates a quaternion given a yaw, pitch, and roll value.
public static Quaternion RotationYawPitchRoll(float yaw, float pitch, float roll)
Parameters
Returns
- Quaternion
The newly created quaternion.
RotationYawPitchRoll(float, float, float, out Quaternion)
Creates a quaternion given a yaw, pitch, and roll value.
public static void RotationYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result)
Parameters
yawfloatThe yaw of rotation.
pitchfloatThe pitch of rotation.
rollfloatThe roll of rotation.
resultQuaternionWhen the method completes, contains the newly created quaternion.
Set(ref Quaternion, int, float)
Sets the specified q.
public static void Set(ref Quaternion q, int index, float value)
Parameters
qQuaternionThe q.
indexintThe index.
valuefloatThe value.
Exceptions
- ArgumentOutOfRangeException
index - Indices for Quaternion run from 0 to 3, inclusive.
Squad(Quaternion, Quaternion, Quaternion, Quaternion, float)
Interpolates between quaternions, using spherical quadrangle interpolation.
public static Quaternion Squad(Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4, float amount)
Parameters
value1QuaternionFirst source quaternion.
value2QuaternionSecond source quaternion.
value3QuaternionThird source quaternion.
value4QuaternionFourth source quaternion.
amountfloatValue between 0 and 1 indicating the weight of interpolation.
Returns
- Quaternion
The spherical quadrangle interpolation of the quaternions.
Squad(ref Quaternion, ref Quaternion, ref Quaternion, ref Quaternion, float, out Quaternion)
Interpolates between quaternions, using spherical quadrangle interpolation.
public static void Squad(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, ref Quaternion value4, float amount, out Quaternion result)
Parameters
value1QuaternionFirst source quaternion.
value2QuaternionSecond source quaternion.
value3QuaternionThird source quaternion.
value4QuaternionFourth source quaternion.
amountfloatValue between 0 and 1 indicating the weight of interpolation.
resultQuaternionWhen the method completes, contains the spherical quadrangle interpolation of the quaternions.
SquadSetup(Quaternion, Quaternion, Quaternion, Quaternion)
Sets up control points for spherical quadrangle interpolation.
public static Quaternion[] SquadSetup(Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4)
Parameters
value1QuaternionFirst source quaternion.
value2QuaternionSecond source quaternion.
value3QuaternionThird source quaternion.
value4QuaternionFourth source quaternion.
Returns
- Quaternion[]
An array of three quaternions that represent control points for spherical quadrangle interpolation.
ToArray(Quaternion)
Creates an array containing the elements of the quaternion.
public static float[] ToArray(this Quaternion q)
Parameters
Returns
- float[]
A four-element array containing the components of the quaternion.
ToMatrix(Quaternion)
public static Matrix4x4 ToMatrix(this Quaternion rotation)
Parameters
rotationQuaternion