struct TQuaternion

template<typename T>

Represents a quaternion used for 3D rotations.

Public

Constructors

TQuaternion<T>

TQuaternion<T>() = default

TQuaternion<T>

TQuaternion<T>(const TQuaternion<T> &) = default

TQuaternion<T>

constexpr TQuaternion<T>(ZeroTag zero)

TQuaternion<T>

constexpr TQuaternion<T>(IdentityTag)

TQuaternion<T>

constexpr TQuaternion<T>(T w, T x, T y, T z)

TQuaternion<T>

explicit TQuaternion<T>(const TMatrix3<T> &rot)

Construct a quaternion from a rotation matrix.

TQuaternion<T>

explicit TQuaternion<T>(const TVector3<T> &axis, const TRadian<T> &angle)

Construct a quaternion from an angle/axis.

TQuaternion<T>

explicit TQuaternion<T>(const TVector3<T> &xaxis, const TVector3<T> &yaxis, const TVector3<T> &zaxis)

Construct a quaternion from 3 orthonormal local axes.

TQuaternion<T>

explicit TQuaternion<T>(const TRadian<T> &xAngle, const TRadian<T> &yAngle, const TRadian<T> &zAngle)

Construct a quaternion from euler angles, YXZ ordering.

TQuaternion<T>

explicit TQuaternion<T>(const TRadian<T> &xAngle, const TRadian<T> &yAngle, const TRadian<T> &zAngle, EulerAngleOrder order)

Construct a quaternion from euler angles, custom ordering.

TQuaternion

TQuaternion() = default

TQuaternion

TQuaternion(const TQuaternion<float> &) noexcept = default

TQuaternion

constexpr TQuaternion(ZeroTag zero)

TQuaternion

constexpr TQuaternion(IdentityTag)

TQuaternion

constexpr TQuaternion(float w, float x, float y, float z)

TQuaternion

explicit TQuaternion(const TMatrix3<float> &rot)

Construct a quaternion from a rotation matrix.

TQuaternion

explicit TQuaternion(const TVector3<float> &axis, const TRadian<float> &angle)

Construct a quaternion from an angle/axis.

TQuaternion

explicit TQuaternion(const TVector3<float> &xaxis, const TVector3<float> &yaxis, const TVector3<float> &zaxis)

Construct a quaternion from 3 orthonormal local axes.

TQuaternion

explicit TQuaternion(const TRadian<float> &xAngle, const TRadian<float> &yAngle, const TRadian<float> &zAngle)

Construct a quaternion from euler angles, YXZ ordering.

TQuaternion

explicit TQuaternion(const TRadian<float> &xAngle, const TRadian<float> &yAngle, const TRadian<float> &zAngle, EulerAngleOrder order)

Construct a quaternion from euler angles, custom ordering.

TQuaternion

TQuaternion() = default

TQuaternion

TQuaternion(const TQuaternion<double> &) = default

TQuaternion

constexpr TQuaternion(ZeroTag zero)

TQuaternion

constexpr TQuaternion(IdentityTag)

TQuaternion

constexpr TQuaternion(double w, double x, double y, double z)

TQuaternion

explicit TQuaternion(const TMatrix3<double> &rot)

Construct a quaternion from a rotation matrix.

TQuaternion

explicit TQuaternion(const TVector3<double> &axis, const TRadian<double> &angle)

Construct a quaternion from an angle/axis.

TQuaternion

explicit TQuaternion(const TVector3<double> &xaxis, const TVector3<double> &yaxis, const TVector3<double> &zaxis)

Construct a quaternion from 3 orthonormal local axes.

TQuaternion

explicit TQuaternion(const TRadian<double> &xAngle, const TRadian<double> &yAngle, const TRadian<double> &zAngle)

Construct a quaternion from euler angles, YXZ ordering.

TQuaternion

explicit TQuaternion(const TRadian<double> &xAngle, const TRadian<double> &yAngle, const TRadian<double> &zAngle, EulerAngleOrder order)

Construct a quaternion from euler angles, custom ordering.

Methods

Swap

void Swap(TQuaternion<T> &other)

Exchange the contents of this quaternion with another.

FromRotationMatrix

void FromRotationMatrix(const TMatrix3<T> &mat)

Initializes the quaternion from a 3x3 rotation matrix.

FromAxisAngle

void FromAxisAngle(const TVector3<T> &axis, const TRadian<T> &angle)

Initializes the quaternion from an angle axis pair.

Quaternion will represent a rotation of "angle" radians around "axis".

FromAxes

void FromAxes(const TVector3<T> &xAxis, const TVector3<T> &yAxis, const TVector3<T> &zAxis)

Initializes the quaternion from orthonormal set of axes.

Quaternion will represent a rotation from base axes to the specified set of axes.

FromEulerAngles

void FromEulerAngles(const TRadian<T> &xAngle, const TRadian<T> &yAngle, const TRadian<T> &zAngle)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

FromEulerAngles

void FromEulerAngles(const TRadian<T> &xAngle, const TRadian<T> &yAngle, const TRadian<T> &zAngle, EulerAngleOrder order)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)
order
The order in which rotations will be extracted. Different values can be retrieved depending on the order.

ToRotationMatrix

void ToRotationMatrix(TMatrix3<T> &mat) const

Converts a quaternion to a rotation matrix.

ToAxisAngle

void ToAxisAngle(TVector3<T> &axis, TRadian<T> &angle) const

Converts a quaternion to an angle axis pair.

axis
The axis around the which rotation takes place.
angle
The angle in radians determining amount of rotation around the axis.

ToAxes

void ToAxes(TVector3<T> &xAxis, TVector3<T> &yAxis, TVector3<T> &zAxis) const

Converts a quaternion to an orthonormal set of axes.

xAxis
The X axis.
yAxis
The Y axis.
zAxis
The Z axis.

ToEulerAngles

bool ToEulerAngles(TRadian<T> &xAngle, TRadian<T> &yAngle, TRadian<T> &zAngle) const

Extracts Pitch/Yaw/Roll rotations from this quaternion.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

Returns: True if unique solution was found, false otherwise.

XAxis

TVector3<T> XAxis() const

Gets the positive x-axis of the coordinate system transformed by this quaternion.

YAxis

TVector3<T> YAxis() const

Gets the positive y-axis of the coordinate system transformed by this quaternion.

ZAxis

TVector3<T> ZAxis() const

Gets the positive z-axis of the coordinate system transformed by this quaternion.

Dot

T Dot(const TQuaternion<T> &other) const

Calculates the dot product of this quaternion and another.

Inverse

TQuaternion<T> Inverse() const

Gets the inverse.

Rotate

TVector3<T> Rotate(const TVector3<T> &vec) const

Rotates the provided vector.

LookRotation

void LookRotation(const TVector3<T> &forwardDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.

LookRotation

void LookRotation(const TVector3<T> &forwardDir, const TVector3<T> &upDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.
upDir
Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel.

IsNaN

bool IsNaN() const

Query if any of the components of the quaternion are not a number.

staticDot

static T Dot(const TQuaternion<T> &lhs, const TQuaternion<T> &rhs)

Calculates the dot product between two quaternions.

staticSlerp

static TQuaternion<T> Slerp(T t, const TQuaternion<T> &p, const TQuaternion<T> &q, bool shortestPath = true)

Performs spherical interpolation between two quaternions.

Spherical interpolation neatly interpolates between two rotations without modifying the size of the vector it is applied to (unlike linear interpolation).

staticLerp

static TQuaternion<T> Lerp(T t, const TQuaternion<T> &a, const TQuaternion<T> &b)

Linearly interpolates between the two quaternions using . t should be in [0, 1] range, where t = 0 corresponds to the left vector, while t = 1 corresponds to the right vector.

staticGetRotationFromTo

static TQuaternion<T> GetRotationFromTo(const TVector3<T> &from, const TVector3<T> &dest, const TVector3<T> &fallbackAxis = TVector3<T>::kZero)

Gets the shortest arc quaternion to rotate this vector to the destination vector.

staticMin

static TQuaternion<T> Min(const TQuaternion<T> &a, const TQuaternion<T> &b)

Returns the minimum of all the quaternion components as a new quaternion.

staticMax

static TQuaternion<T> Max(const TQuaternion<T> &a, const TQuaternion<T> &b)

Returns the maximum of all the quaternion components as a new quaternion.

Swap

void Swap(TQuaternion<float> &other)

Exchange the contents of this quaternion with another.

FromRotationMatrix

void FromRotationMatrix(const TMatrix3<float> &mat)

Initializes the quaternion from a 3x3 rotation matrix.

FromAxisAngle

void FromAxisAngle(const TVector3<float> &axis, const TRadian<float> &angle)

Initializes the quaternion from an angle axis pair.

Quaternion will represent a rotation of "angle" radians around "axis".

FromAxes

void FromAxes(const TVector3<float> &xAxis, const TVector3<float> &yAxis, const TVector3<float> &zAxis)

Initializes the quaternion from orthonormal set of axes.

Quaternion will represent a rotation from base axes to the specified set of axes.

FromEulerAngles

void FromEulerAngles(const TRadian<float> &xAngle, const TRadian<float> &yAngle, const TRadian<float> &zAngle)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

FromEulerAngles

void FromEulerAngles(const TRadian<float> &xAngle, const TRadian<float> &yAngle, const TRadian<float> &zAngle, EulerAngleOrder order)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)
order
The order in which rotations will be extracted. Different values can be retrieved depending on the order.

ToRotationMatrix

void ToRotationMatrix(TMatrix3<float> &mat) const

Converts a quaternion to a rotation matrix.

ToAxisAngle

void ToAxisAngle(TVector3<float> &axis, TRadian<float> &angle) const

Converts a quaternion to an angle axis pair.

axis
The axis around the which rotation takes place.
angle
The angle in radians determining amount of rotation around the axis.

ToAxes

void ToAxes(TVector3<float> &xAxis, TVector3<float> &yAxis, TVector3<float> &zAxis) const

Converts a quaternion to an orthonormal set of axes.

xAxis
The X axis.
yAxis
The Y axis.
zAxis
The Z axis.

ToEulerAngles

bool ToEulerAngles(TRadian<float> &xAngle, TRadian<float> &yAngle, TRadian<float> &zAngle) const

Extracts Pitch/Yaw/Roll rotations from this quaternion.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

Returns: True if unique solution was found, false otherwise.

XAxis

TVector3<float> XAxis() const

Gets the positive x-axis of the coordinate system transformed by this quaternion.

YAxis

TVector3<float> YAxis() const

Gets the positive y-axis of the coordinate system transformed by this quaternion.

ZAxis

TVector3<float> ZAxis() const

Gets the positive z-axis of the coordinate system transformed by this quaternion.

Dot

float Dot(const TQuaternion<float> &other) const

Calculates the dot product of this quaternion and another.

Inverse

TQuaternion<float> Inverse() const

Gets the inverse.

Rotate

TVector3<float> Rotate(const TVector3<float> &vec) const

Rotates the provided vector.

LookRotation

void LookRotation(const TVector3<float> &forwardDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.

LookRotation

void LookRotation(const TVector3<float> &forwardDir, const TVector3<float> &upDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.
upDir
Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel.

IsNaN

bool IsNaN() const

Query if any of the components of the quaternion are not a number.

staticDot

static float Dot(const TQuaternion<float> &lhs, const TQuaternion<float> &rhs)

Calculates the dot product between two quaternions.

staticSlerp

static TQuaternion<float> Slerp(float t, const TQuaternion<float> &p, const TQuaternion<float> &q, bool shortestPath)

Performs spherical interpolation between two quaternions.

Spherical interpolation neatly interpolates between two rotations without modifying the size of the vector it is applied to (unlike linear interpolation).

staticLerp

static TQuaternion<float> Lerp(float t, const TQuaternion<float> &a, const TQuaternion<float> &b)

Linearly interpolates between the two quaternions using . t should be in [0, 1] range, where t = 0 corresponds to the left vector, while t = 1 corresponds to the right vector.

staticGetRotationFromTo

static TQuaternion<float> GetRotationFromTo(const TVector3<float> &from, const TVector3<float> &dest, const TVector3<float> &fallbackAxis)

Gets the shortest arc quaternion to rotate this vector to the destination vector.

staticMin

static TQuaternion<float> Min(const TQuaternion<float> &a, const TQuaternion<float> &b)

Returns the minimum of all the quaternion components as a new quaternion.

staticMax

static TQuaternion<float> Max(const TQuaternion<float> &a, const TQuaternion<float> &b)

Returns the maximum of all the quaternion components as a new quaternion.

Swap

void Swap(TQuaternion<double> &other)

Exchange the contents of this quaternion with another.

FromRotationMatrix

void FromRotationMatrix(const TMatrix3<double> &mat)

Initializes the quaternion from a 3x3 rotation matrix.

FromAxisAngle

void FromAxisAngle(const TVector3<double> &axis, const TRadian<double> &angle)

Initializes the quaternion from an angle axis pair.

Quaternion will represent a rotation of "angle" radians around "axis".

FromAxes

void FromAxes(const TVector3<double> &xAxis, const TVector3<double> &yAxis, const TVector3<double> &zAxis)

Initializes the quaternion from orthonormal set of axes.

Quaternion will represent a rotation from base axes to the specified set of axes.

FromEulerAngles

void FromEulerAngles(const TRadian<double> &xAngle, const TRadian<double> &yAngle, const TRadian<double> &zAngle)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

FromEulerAngles

void FromEulerAngles(const TRadian<double> &xAngle, const TRadian<double> &yAngle, const TRadian<double> &zAngle, EulerAngleOrder order)

Creates a quaternion from the provided Pitch/Yaw/Roll angles.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)
order
The order in which rotations will be extracted. Different values can be retrieved depending on the order.

ToRotationMatrix

void ToRotationMatrix(TMatrix3<double> &mat) const

Converts a quaternion to a rotation matrix.

ToAxisAngle

void ToAxisAngle(TVector3<double> &axis, TRadian<double> &angle) const

Converts a quaternion to an angle axis pair.

axis
The axis around the which rotation takes place.
angle
The angle in radians determining amount of rotation around the axis.

ToAxes

void ToAxes(TVector3<double> &xAxis, TVector3<double> &yAxis, TVector3<double> &zAxis) const

Converts a quaternion to an orthonormal set of axes.

xAxis
The X axis.
yAxis
The Y axis.
zAxis
The Z axis.

ToEulerAngles

bool ToEulerAngles(TRadian<double> &xAngle, TRadian<double> &yAngle, TRadian<double> &zAngle) const

Extracts Pitch/Yaw/Roll rotations from this quaternion.

xAngle
Rotation about x axis. (AKA Pitch)
yAngle
Rotation about y axis. (AKA Yaw)
zAngle
Rotation about z axis. (AKA Roll)

Returns: True if unique solution was found, false otherwise.

XAxis

TVector3<double> XAxis() const

Gets the positive x-axis of the coordinate system transformed by this quaternion.

YAxis

TVector3<double> YAxis() const

Gets the positive y-axis of the coordinate system transformed by this quaternion.

ZAxis

TVector3<double> ZAxis() const

Gets the positive z-axis of the coordinate system transformed by this quaternion.

Dot

double Dot(const TQuaternion<double> &other) const

Calculates the dot product of this quaternion and another.

Inverse

TQuaternion<double> Inverse() const

Gets the inverse.

Rotate

TVector3<double> Rotate(const TVector3<double> &vec) const

Rotates the provided vector.

LookRotation

void LookRotation(const TVector3<double> &forwardDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.

LookRotation

void LookRotation(const TVector3<double> &forwardDir, const TVector3<double> &upDir)

Orients the quaternion so its negative z axis points to the provided direction.

forwardDir
Direction to orient towards.
upDir
Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel.

IsNaN

bool IsNaN() const

Query if any of the components of the quaternion are not a number.

staticDot

static double Dot(const TQuaternion<double> &lhs, const TQuaternion<double> &rhs)

Calculates the dot product between two quaternions.

staticSlerp

static TQuaternion<double> Slerp(double t, const TQuaternion<double> &p, const TQuaternion<double> &q, bool shortestPath)

Performs spherical interpolation between two quaternions.

Spherical interpolation neatly interpolates between two rotations without modifying the size of the vector it is applied to (unlike linear interpolation).

staticLerp

static TQuaternion<double> Lerp(double t, const TQuaternion<double> &a, const TQuaternion<double> &b)

Linearly interpolates between the two quaternions using . t should be in [0, 1] range, where t = 0 corresponds to the left vector, while t = 1 corresponds to the right vector.

staticGetRotationFromTo

static TQuaternion<double> GetRotationFromTo(const TVector3<double> &from, const TVector3<double> &dest, const TVector3<double> &fallbackAxis)

Gets the shortest arc quaternion to rotate this vector to the destination vector.

staticMin

static TQuaternion<double> Min(const TQuaternion<double> &a, const TQuaternion<double> &b)

Returns the minimum of all the quaternion components as a new quaternion.

staticMax

static TQuaternion<double> Max(const TQuaternion<double> &a, const TQuaternion<double> &b)

Returns the maximum of all the quaternion components as a new quaternion.

Fields

X

T X

Y

T Y

Z

T Z

W

T W

X

float X

Y

float Y

Z

float Z

W

float W

X

double X

Y

double Y

Z

double Z

W

double W

Operators

operator=

TQuaternion<T> &operator=(const TQuaternion<T> &) = default

operator[]

T operator[](const size_t i) const

operator[]

T &operator[](const size_t i)

operator+

TQuaternion<T> operator+(const TQuaternion<T> &rhs) const

operator-

TQuaternion<T> operator-(const TQuaternion<T> &rhs) const

operator*

TQuaternion<T> operator*(const TQuaternion<T> &rhs) const

operator*

TQuaternion<T> operator*(T rhs) const

operator/

TQuaternion<T> operator/(T rhs) const

operator-

TQuaternion<T> operator-() const

operator==

bool operator==(const TQuaternion<T> &rhs) const

operator!=

bool operator!=(const TQuaternion<T> &rhs) const

operator+=

TQuaternion<T> &operator+=(const TQuaternion<T> &rhs)

operator-=

TQuaternion<T> &operator-=(const TQuaternion<T> &rhs)

operator*=

TQuaternion<T> &operator*=(const TQuaternion<T> &rhs)

operator=

TQuaternion<float> &operator=(const TQuaternion<float> &) noexcept = default

operator[]

float operator[](const size_t i) const

operator[]

float &operator[](const size_t i)

operator+

TQuaternion<float> operator+(const TQuaternion<float> &rhs) const

operator-

TQuaternion<float> operator-(const TQuaternion<float> &rhs) const

operator*

TQuaternion<float> operator*(const TQuaternion<float> &rhs) const

operator*

TQuaternion<float> operator*(float rhs) const

operator/

TQuaternion<float> operator/(float rhs) const

operator-

TQuaternion<float> operator-() const

operator==

bool operator==(const TQuaternion<float> &rhs) const

operator!=

bool operator!=(const TQuaternion<float> &rhs) const

operator+=

TQuaternion<float> &operator+=(const TQuaternion<float> &rhs)

operator-=

TQuaternion<float> &operator-=(const TQuaternion<float> &rhs)

operator*=

TQuaternion<float> &operator*=(const TQuaternion<float> &rhs)

operator=

TQuaternion<double> &operator=(const TQuaternion<double> &) = default

operator[]

double operator[](const size_t i) const

operator[]

double &operator[](const size_t i)

operator+

TQuaternion<double> operator+(const TQuaternion<double> &rhs) const

operator-

TQuaternion<double> operator-(const TQuaternion<double> &rhs) const

operator*

TQuaternion<double> operator*(const TQuaternion<double> &rhs) const

operator*

TQuaternion<double> operator*(double rhs) const

operator/

TQuaternion<double> operator/(double rhs) const

operator-

TQuaternion<double> operator-() const

operator==

bool operator==(const TQuaternion<double> &rhs) const

operator!=

bool operator!=(const TQuaternion<double> &rhs) const

operator+=

TQuaternion<double> &operator+=(const TQuaternion<double> &rhs)

operator-=

TQuaternion<double> &operator-=(const TQuaternion<double> &rhs)

operator*=

TQuaternion<double> &operator*=(const TQuaternion<double> &rhs)