#include <AH/Math/Quaternion.hpp>
Type for quaternions of floating point numbers.
Quaternions can be multiplied (Hamiltonian product), normalized and can perform rotations of vectors. Quaternion also has an implementation of the following operators:
-
(conjugate)+
, +=
, -
, -=
(Hamiltonian product of quaternions, adds and subtracts angles)*
, *=
, /
, /=
(multiplication and division by scalars)==
, !=
(equality)<<
(printing) Definition at line 60 of file Quaternion.hpp.
Public Member Functions | |
Quaternion ()=default | |
Create a quaternion that is initialized to the identity quaternion. More... | |
Quaternion (float w, float x, float y, float z) | |
Create a quaterion with the given values for w, x, y and z. More... | |
Quaternion & | operator+= (Quaternion rhs) |
Sum of two quaterions uses quaternion multiplication. More... | |
Quaternion | operator+ (Quaternion rhs) const |
Sum of two quaternions uses quaternion multiplication. More... | |
Quaternion | conjugated () const |
Complex conjugate (doesn't change the original quaternion). More... | |
Quaternion | operator- () const |
Negated quaternion is its conjugate. More... | |
Quaternion & | operator-= (Quaternion rhs) |
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b . More... | |
Quaternion | operator- (Quaternion rhs) const |
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b . More... | |
Quaternion & | operator*= (float rhs) |
Scalar multiplication. More... | |
Quaternion | operator* (float rhs) const |
Scalar multiplication. More... | |
Quaternion & | operator/= (float rhs) |
Scalar division. More... | |
Quaternion | operator/ (float rhs) const |
Scalar division. More... | |
float | normSquared () const |
Norm squared. More... | |
float | norm () const |
Norm. More... | |
Quaternion & | normalize () |
Normalize this quaternion. More... | |
Quaternion | normalized () const |
Normalize a copy of this quaternion (doesn't change the original quaternion). More... | |
Vec3f | rotate (Vec3f v) const |
Rotate vector by this quaternion. More... | |
bool | operator== (Quaternion rhs) const |
Equality check. More... | |
bool | operator!= (Quaternion rhs) const |
Inequality check. More... | |
Static Public Member Functions | |
static Quaternion | identity () |
Identity quaternion (1,0,0,0). More... | |
static Quaternion | fromDirection (Vec3f v) |
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v.normalized() . More... | |
static Quaternion | fromXYAngle (float xAngle, float yAngle) |
Calculate the quaternion from a vector that makes a given angle with the XZ plane and a given angle with the YZ plane. More... | |
static Quaternion | hamiltonianProduct (Quaternion q, Quaternion r) |
Quaternion multiplication. More... | |
Public Attributes | |
float | w = 1.0 |
Scalar (real) component. More... | |
float | x = 0.0 |
First vector (imaginary) component \( \mathbf{i} \). More... | |
float | y = 0.0 |
Second vector (imaginary) component \( \mathbf{j} \). More... | |
float | z = 0.0 |
Third vector (imaginary) component \( \mathbf{k} \). More... | |
Related Functions | |
(Note that these are not member functions.) | |
Quaternion | operator* (float lhs, Quaternion rhs) |
Scalar multiplication. More... | |
Print & | operator<< (Print &os, Quaternion e) |
Printing. More... | |
|
default |
Create a quaternion that is initialized to the identity quaternion.
|
inline |
Create a quaterion with the given values for w, x, y and z.
Definition at line 69 of file Quaternion.hpp.
|
inline |
Sum of two quaterions uses quaternion multiplication.
(Composition of the two rotations.)
Definition at line 73 of file Quaternion.hpp.
|
inline |
Sum of two quaternions uses quaternion multiplication.
(Composition of the two rotations.)
Definition at line 78 of file Quaternion.hpp.
|
inline |
Complex conjugate (doesn't change the original quaternion).
Definition at line 83 of file Quaternion.hpp.
|
inline |
Negated quaternion is its conjugate.
Definition at line 85 of file Quaternion.hpp.
|
inline |
Difference of two quaternions a
and b
is the quaternion multiplication of a
and the conjugate of b
.
(Composition of the rotation of a
and the inverse rotation of b
.)
Definition at line 90 of file Quaternion.hpp.
|
inline |
Difference of two quaternions a
and b
is the quaternion multiplication of a
and the conjugate of b
.
(Composition of the rotation of a
and the inverse rotation of b
.)
Definition at line 94 of file Quaternion.hpp.
|
inline |
Scalar multiplication.
Definition at line 101 of file Quaternion.hpp.
|
inline |
Scalar multiplication.
Definition at line 109 of file Quaternion.hpp.
|
inline |
Scalar division.
Definition at line 116 of file Quaternion.hpp.
|
inline |
Scalar division.
Definition at line 124 of file Quaternion.hpp.
|
inline |
Norm squared.
Definition at line 131 of file Quaternion.hpp.
|
inline |
Norm.
Definition at line 133 of file Quaternion.hpp.
|
inline |
Normalize this quaternion.
Definition at line 135 of file Quaternion.hpp.
|
inline |
Normalize a copy of this quaternion (doesn't change the original quaternion).
Definition at line 138 of file Quaternion.hpp.
Rotate vector by this quaternion.
This function uses the normalized version of this quaternion.
quatrotate
in MATLAB! MATLAB rotates by the conjugate of the quaternion, while this function rotates by the quaternion itself. Definition at line 149 of file Quaternion.hpp.
|
inline |
Equality check.
Definition at line 179 of file Quaternion.hpp.
|
inline |
Inequality check.
Definition at line 184 of file Quaternion.hpp.
|
inlinestatic |
Identity quaternion (1,0,0,0).
Definition at line 187 of file Quaternion.hpp.
|
inlinestatic |
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v.normalized()
.
Definition at line 193 of file Quaternion.hpp.
|
inlinestatic |
Calculate the quaternion from a vector that makes a given angle with the XZ plane and a given angle with the YZ plane.
xAngle | The angle the vector should make with the XZ plane. A positive value represents a positive rotation about the x-axis. |
yAngle | The angle the vector should make with the YZ plane. A positive value represents a positive rotation about the y-axis. |
Definition at line 256 of file Quaternion.hpp.
|
inlinestatic |
Quaternion multiplication.
Definition at line 266 of file Quaternion.hpp.
float w = 1.0 |
Scalar (real) component.
Definition at line 61 of file Quaternion.hpp.
float x = 0.0 |
First vector (imaginary) component \( \mathbf{i} \).
Definition at line 62 of file Quaternion.hpp.
float y = 0.0 |
Second vector (imaginary) component \( \mathbf{j} \).
Definition at line 63 of file Quaternion.hpp.
float z = 0.0 |
Third vector (imaginary) component \( \mathbf{k} \).
Definition at line 64 of file Quaternion.hpp.