Control Surface master MIDI Control Surface library for Arduino
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:

• - (conjugate)
• +, +=, -, -= (Hamiltonian product of quaternions, adds and subtracts angles)
• *, *=, /, /= (multiplication and division by scalars)
• ==, != (equality)
• << (printing)

Definition at line 60 of file Quaternion.hpp.

Collaboration diagram for Quaternion:

## 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...

Quaternionoperator+= (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...

Quaternionoperator-= (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...

Quaternionoperator*= (float rhs)
Scalar multiplication. More...

Quaternion operator* (float rhs) const
Scalar multiplication. More...

Quaternionoperator/= (float rhs)
Scalar division. More...

Quaternion operator/ (float rhs) const
Scalar division. More...

float normSquared () const
Norm squared. More...

float norm () const
Norm. More...

Quaternionnormalize ()
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...

## ◆ 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 69 of file Quaternion.hpp.

## ◆ operator+=()

 Quaternion & operator+= ( Quaternion rhs )
inline

Sum of two quaterions uses quaternion multiplication.

(Composition of the two rotations.)

Definition at line 73 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 78 of file Quaternion.hpp.

## ◆ conjugated()

 Quaternion conjugated ( ) const
inline

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

Definition at line 83 of file Quaternion.hpp.

## ◆ operator-() [1/2]

 Quaternion operator- ( ) const
inline

Negated quaternion is its conjugate.

Definition at line 85 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 90 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 94 of file Quaternion.hpp.

## ◆ operator*=()

 Quaternion & operator*= ( float rhs )
inline

Scalar multiplication.

Definition at line 101 of file Quaternion.hpp.

## ◆ operator*()

 Quaternion operator* ( float rhs ) const
inline

Scalar multiplication.

Definition at line 109 of file Quaternion.hpp.

## ◆ operator/=()

 Quaternion & operator/= ( float rhs )
inline

Scalar division.

Definition at line 116 of file Quaternion.hpp.

## ◆ operator/()

 Quaternion operator/ ( float rhs ) const
inline

Scalar division.

Definition at line 124 of file Quaternion.hpp.

## ◆ normSquared()

 float normSquared ( ) const
inline

Norm squared.

Definition at line 131 of file Quaternion.hpp.

## ◆ norm()

 float norm ( ) const
inline

Norm.

Definition at line 133 of file Quaternion.hpp.

## ◆ normalize()

 Quaternion & normalize ( )
inline

Normalize this quaternion.

Definition at line 135 of file Quaternion.hpp.

## ◆ normalized()

 Quaternion normalized ( ) const
inline

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

Definition at line 138 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 149 of file Quaternion.hpp.

## ◆ operator==()

 bool operator== ( Quaternion rhs ) const
inline

Equality check.

Definition at line 179 of file Quaternion.hpp.

## ◆ operator!=()

 bool operator!= ( Quaternion rhs ) const
inline

Inequality check.

Definition at line 184 of file Quaternion.hpp.

## ◆ identity()

 static Quaternion identity ( )
inlinestatic

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

Definition at line 187 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 193 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
 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.
Returns
A quaternion from the vector {tan(yAngle), -tan(xAngle), 1}.

Definition at line 256 of file Quaternion.hpp.

## ◆ hamiltonianProduct()

 static Quaternion hamiltonianProduct ( Quaternion q, Quaternion r )
inlinestatic

Quaternion multiplication.

Definition at line 266 of file Quaternion.hpp.

## ◆ w

 float w = 1.0

Scalar (real) component.

Definition at line 61 of file Quaternion.hpp.

## ◆ x

 float x = 0.0

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

Definition at line 62 of file Quaternion.hpp.

## ◆ y

 float y = 0.0

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

Definition at line 63 of file Quaternion.hpp.

## ◆ z

 float z = 0.0

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

Definition at line 64 of file Quaternion.hpp.

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