Table of Contents

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

Quaternion

One

A Quaternion with all of its components set to one.

public static readonly Quaternion One

Field Value

Quaternion

SizeInBytes

The size of the Quaternion type, in bytes.

public static readonly int SizeInBytes

Field Value

int

Zero

A Quaternion with all of its components set to zero.

public static readonly Quaternion Zero

Field Value

Quaternion

Methods

Angle(Quaternion)

Gets the angle of the quaternion.

public static float Angle(this Quaternion q)

Parameters

q Quaternion

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

source Quaternion

The first Quaternion

other Quaternion

The second Quaternion

Returns

float

Axis(Quaternion)

Gets the axis components of the quaternion.

public static Vector3 Axis(this Quaternion q)

Parameters

q Quaternion

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

value1 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 1 of the triangle.

value2 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 2 of the triangle.

value3 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 3 of the triangle.

amount1 float

Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in value2).

amount2 float

Barycentric 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

value1 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 1 of the triangle.

value2 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 2 of the triangle.

value3 Quaternion

A Quaternion containing the 4D Cartesian coordinates of vertex 3 of the triangle.

amount1 float

Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in value2).

amount2 float

Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in value3).

result Quaternion

When 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

source Vector3

The source vector of the transformation.

target Vector3

The 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

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The 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

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

result Quaternion

When 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

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The 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

objectPosition Vector3

The position of the object around which the billboard will rotate.

cameraPosition Vector3

The position of the camera.

cameraUpVector Vector3

The up vector of the camera.

cameraForwardVector Vector3

The forward vector of the camera.

result Quaternion

When the method completes, contains the created billboard quaternion.

Exponential(Quaternion)

Exponentiates a quaternion.

public static Quaternion Exponential(Quaternion value)

Parameters

value Quaternion

The 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

value Quaternion

The quaternion to exponentiate.

result Quaternion

When 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

q Quaternion
index int

The 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 index is 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

q Quaternion

Returns

bool

Logarithm(Quaternion)

Calculates the natural logarithm of the specified quaternion.

public static Quaternion Logarithm(Quaternion value)

Parameters

value Quaternion

The 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

value Quaternion

The quaternion whose logarithm will be calculated.

result Quaternion

When 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

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The 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

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

result Quaternion

When 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

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The 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

eye Vector3

The position of the viewer's eye.

target Vector3

The camera look-at target.

up Vector3

The camera's up vector.

result Quaternion

When 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

value Quaternion

The quaternion.

vector Vector3

The 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

value Quaternion

The quaternion.

vector Vector3

The vector to rotate.

RotationAxis(Vector3, float)

Creates a quaternion given a rotation and an axis.

public static Quaternion RotationAxis(Vector3 axis, float angle)

Parameters

axis Vector3

The axis of rotation.

angle float

The angle of rotation.

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

axis Vector3

The axis of rotation.

angle float

The angle of rotation.

result Quaternion

When 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

forward Vector3

The camera's forward direction.

up Vector3

The camera's up vector.

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

forward Vector3

The camera's forward direction.

up Vector3

The camera's up vector.

result Quaternion

When 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

forward Vector3

The camera's forward direction.

up Vector3

The camera's up vector.

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

forward Vector3

The camera's forward direction.

up Vector3

The camera's up vector.

result Quaternion

When 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

matrix Matrix3x3

The rotation matrix.

result Quaternion

When the method completes, contains the newly created quaternion.

RotationMatrix(Matrix4x4)

Creates a quaternion given a rotation matrix.

public static Quaternion RotationMatrix(Matrix4x4 matrix)

Parameters

matrix Matrix4x4

The 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

matrix Matrix4x4

The rotation matrix.

result Quaternion

When 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

yaw float

The yaw of rotation.

pitch float

The pitch of rotation.

roll float

The roll of rotation.

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

yaw float

The yaw of rotation.

pitch float

The pitch of rotation.

roll float

The roll of rotation.

result Quaternion

When 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

q Quaternion

The q.

index int

The index.

value float

The 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

value1 Quaternion

First source quaternion.

value2 Quaternion

Second source quaternion.

value3 Quaternion

Third source quaternion.

value4 Quaternion

Fourth source quaternion.

amount float

Value 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

value1 Quaternion

First source quaternion.

value2 Quaternion

Second source quaternion.

value3 Quaternion

Third source quaternion.

value4 Quaternion

Fourth source quaternion.

amount float

Value between 0 and 1 indicating the weight of interpolation.

result Quaternion

When 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

value1 Quaternion

First source quaternion.

value2 Quaternion

Second source quaternion.

value3 Quaternion

Third source quaternion.

value4 Quaternion

Fourth 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

q Quaternion

Returns

float[]

A four-element array containing the components of the quaternion.

ToMatrix(Quaternion)

public static Matrix4x4 ToMatrix(this Quaternion rotation)

Parameters

rotation Quaternion

Returns

Matrix4x4