Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Related Symbols | List of all members
Quaternion Struct Reference

#include <AH/Math/Quaternion.hpp>

Detailed Description

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:

Definition at line 57 of file Quaternion.hpp.

+ Collaboration diagram for Quaternion:

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.
 
Quaternionoperator+= (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.
 
Quaternionoperator-= (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.
 
Quaternionoperator*= (float rhs)
 Scalar multiplication.
 
Quaternion operator* (float rhs) const
 Scalar multiplication.
 
Quaternionoperator/= (float rhs)
 Scalar division.
 
Quaternion operator/ (float rhs) const
 Scalar division.
 
float normSquared () const
 Norm squared.
 
float norm () const
 Norm.
 
Quaternionnormalize ()
 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.
 

Constructor & Destructor Documentation

◆ Quaternion() [1/2]

Quaternion ( )
default

Create a quaternion that is initialized to the identity quaternion.

◆ Quaternion() [2/2]

Quaternion ( float w,
float x,
float y,
float z )
inline

Create a quaterion with the given values for w, x, y and z.

Definition at line 66 of file Quaternion.hpp.

Member Function Documentation

◆ operator+=()

Quaternion & operator+= ( Quaternion rhs)
inline

Sum of two quaterions uses quaternion multiplication.

(Composition of the two rotations.)

Definition at line 70 of file Quaternion.hpp.

◆ operator+()

Quaternion operator+ ( Quaternion rhs) const
inline

Sum of two quaternions uses quaternion multiplication.

(Composition of the two rotations.)

Definition at line 75 of file Quaternion.hpp.

◆ conjugated()

Quaternion conjugated ( ) const
inline

Complex conjugate (doesn't change the original quaternion).

Definition at line 80 of file Quaternion.hpp.

◆ operator-() [1/2]

Quaternion operator- ( ) const
inline

Negated quaternion is its conjugate.

Definition at line 82 of file Quaternion.hpp.

◆ operator-=()

Quaternion & operator-= ( Quaternion rhs)
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.

◆ operator-() [2/2]

Quaternion operator- ( Quaternion rhs) const
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.

◆ operator*=()

Quaternion & operator*= ( float rhs)
inline

Scalar multiplication.

Definition at line 98 of file Quaternion.hpp.

◆ operator*()

Quaternion operator* ( float rhs) const
inline

Scalar multiplication.

Definition at line 106 of file Quaternion.hpp.

◆ operator/=()

Quaternion & operator/= ( float rhs)
inline

Scalar division.

Definition at line 113 of file Quaternion.hpp.

◆ operator/()

Quaternion operator/ ( float rhs) const
inline

Scalar division.

Definition at line 121 of file Quaternion.hpp.

◆ normSquared()

float normSquared ( ) const
inline

Norm squared.

Definition at line 128 of file Quaternion.hpp.

◆ norm()

float norm ( ) const
inline

Norm.

Definition at line 130 of file Quaternion.hpp.

◆ normalize()

Quaternion & normalize ( )
inline

Normalize this quaternion.

Definition at line 132 of file Quaternion.hpp.

◆ normalized()

Quaternion normalized ( ) const
inline

Normalize a copy of this quaternion (doesn't change the original quaternion).

Definition at line 135 of file Quaternion.hpp.

◆ rotate()

Vec3f rotate ( Vec3f v) const
inline

Rotate vector by this quaternion.

This function uses the normalized version of this quaternion.

Note
This function is not the same as 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.

◆ operator==()

bool operator== ( Quaternion rhs) const
inline

Equality check.

Definition at line 176 of file Quaternion.hpp.

◆ operator!=()

bool operator!= ( Quaternion rhs) const
inline

Inequality check.

Definition at line 181 of file Quaternion.hpp.

◆ identity()

static Quaternion identity ( )
inlinestatic

Identity quaternion (1,0,0,0).

Definition at line 184 of file Quaternion.hpp.

◆ fromDirection()

static Quaternion fromDirection ( Vec3f v)
inlinestatic

Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v.normalized().

Definition at line 190 of file Quaternion.hpp.

◆ fromXYAngle()

static Quaternion fromXYAngle ( float xAngle,
float yAngle )
inlinestatic

Calculate the quaternion from a vector that makes a given angle with the XZ plane and a given angle with the YZ plane.

Parameters
xAngleThe angle the vector should make with the XZ plane. A positive value represents a positive rotation about the x-axis.
yAngleThe angle the vector should make with the YZ plane. A positive value represents a positive rotation about the y-axis.
Returns
A quaternion from the vector {tan(yAngle), -tan(xAngle), 1}.

Definition at line 253 of file Quaternion.hpp.

◆ hamiltonianProduct()

static Quaternion hamiltonianProduct ( Quaternion q,
Quaternion r )
inlinestatic

Quaternion multiplication.

Definition at line 263 of file Quaternion.hpp.

Member Data Documentation

◆ w

float w = 1.0

Scalar (real) component.

Definition at line 58 of file Quaternion.hpp.

◆ x

float x = 0.0

First vector (imaginary) component \( \mathbf{i} \).

Definition at line 59 of file Quaternion.hpp.

◆ y

float y = 0.0

Second vector (imaginary) component \( \mathbf{j} \).

Definition at line 60 of file Quaternion.hpp.

◆ z

float z = 0.0

Third vector (imaginary) component \( \mathbf{k} \).

Definition at line 61 of file Quaternion.hpp.


The documentation for this struct was generated from the following file: