#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 57 of file Quaternion.hpp.
Public Member Functions | |
Quaternion ()=default | |
Create a quaternion that is initialized to the identity quaternion. | |
Quaternion (float w, float x, float y, float z) | |
Create a quaterion with the given values for w, x, y and z. | |
Quaternion & | operator+= (Quaternion rhs) |
Sum of two quaterions uses quaternion multiplication. | |
Quaternion | operator+ (Quaternion rhs) const |
Sum of two quaternions uses quaternion multiplication. | |
Quaternion | conjugated () const |
Complex conjugate (doesn't change the original quaternion). | |
Quaternion | operator- () const |
Negated quaternion is its conjugate. | |
Quaternion & | operator-= (Quaternion rhs) |
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b . | |
Quaternion | operator- (Quaternion rhs) const |
Difference of two quaternions a and b is the quaternion multiplication of a and the conjugate of b . | |
Quaternion & | operator*= (float rhs) |
Scalar multiplication. | |
Quaternion | operator* (float rhs) const |
Scalar multiplication. | |
Quaternion & | operator/= (float rhs) |
Scalar division. | |
Quaternion | operator/ (float rhs) const |
Scalar division. | |
float | normSquared () const |
Norm squared. | |
float | norm () const |
Norm. | |
Quaternion & | normalize () |
Normalize this quaternion. | |
Quaternion | normalized () const |
Normalize a copy of this quaternion (doesn't change the original quaternion). | |
Vec3f | rotate (Vec3f v) const |
Rotate vector by this quaternion. | |
bool | operator== (Quaternion rhs) const |
Equality check. | |
bool | operator!= (Quaternion rhs) const |
Inequality check. | |
Static Public Member Functions | |
static Quaternion | identity () |
Identity quaternion (1,0,0,0). | |
static Quaternion | fromDirection (Vec3f v) |
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v.normalized() . | |
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. | |
static Quaternion | hamiltonianProduct (Quaternion q, Quaternion r) |
Quaternion multiplication. | |
Public Attributes | |
float | w = 1.0 |
Scalar (real) component. | |
float | x = 0.0 |
First vector (imaginary) component \( \mathbf{i} \). | |
float | y = 0.0 |
Second vector (imaginary) component \( \mathbf{j} \). | |
float | z = 0.0 |
Third vector (imaginary) component \( \mathbf{k} \). | |
Related Symbols | |
(Note that these are not member symbols.) | |
Quaternion | operator* (float lhs, Quaternion rhs) |
Scalar multiplication. | |
Print & | operator<< (Print &os, Quaternion e) |
Printing. | |
|
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 66 of file Quaternion.hpp.
|
inline |
Sum of two quaterions uses quaternion multiplication.
(Composition of the two rotations.)
Definition at line 70 of file Quaternion.hpp.
|
inline |
Sum of two quaternions uses quaternion multiplication.
(Composition of the two rotations.)
Definition at line 75 of file Quaternion.hpp.
|
inline |
Complex conjugate (doesn't change the original quaternion).
Definition at line 80 of file Quaternion.hpp.
|
inline |
Negated quaternion is its conjugate.
Definition at line 82 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 87 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 91 of file Quaternion.hpp.
|
inline |
Scalar multiplication.
Definition at line 98 of file Quaternion.hpp.
|
inline |
Scalar multiplication.
Definition at line 106 of file Quaternion.hpp.
|
inline |
Scalar division.
Definition at line 113 of file Quaternion.hpp.
|
inline |
Scalar division.
Definition at line 121 of file Quaternion.hpp.
|
inline |
Norm squared.
Definition at line 128 of file Quaternion.hpp.
|
inline |
Norm.
Definition at line 130 of file Quaternion.hpp.
|
inline |
Normalize this quaternion.
Definition at line 132 of file Quaternion.hpp.
|
inline |
Normalize a copy of this quaternion (doesn't change the original quaternion).
Definition at line 135 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 146 of file Quaternion.hpp.
|
inline |
Equality check.
Definition at line 176 of file Quaternion.hpp.
|
inline |
Inequality check.
Definition at line 181 of file Quaternion.hpp.
|
inlinestatic |
Identity quaternion (1,0,0,0).
Definition at line 184 of file Quaternion.hpp.
|
inlinestatic |
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v.normalized()
.
Definition at line 190 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 253 of file Quaternion.hpp.
|
inlinestatic |
Quaternion multiplication.
Definition at line 263 of file Quaternion.hpp.
float w = 1.0 |
Scalar (real) component.
Definition at line 58 of file Quaternion.hpp.
float x = 0.0 |
First vector (imaginary) component \( \mathbf{i} \).
Definition at line 59 of file Quaternion.hpp.
float y = 0.0 |
Second vector (imaginary) component \( \mathbf{j} \).
Definition at line 60 of file Quaternion.hpp.
float z = 0.0 |
Third vector (imaginary) component \( \mathbf{k} \).
Definition at line 61 of file Quaternion.hpp.