math::quaternion Class Reference

4-dimensional normed division algebra over the Real Numbers

Every quaternion is uniquely expressible as a Real linear combination of basis quaternions $$1, i, j, k$$ satisfying the relation:

$i^{2} = j^{2} = k^{2} = ijk = -1 \label{ eq. 1 }$

Quaternions satisfy vector space axioms over the Reals. The set $$\mathbf{H}$$ of all quaternions has dimension 4. However, unlike Real and Complex numbers, multiplication of quaternions is not commutative. However, multiplication associates, and every non-zero element has a unique inverse.

The set of equations (eq. 1) is the fundamental formula for quaternion multiplication. The multiplication table of basis quaternions is easily derived from the relation $$ijk = -1$$.

Given quaternion set $$\mathbf{H}$$, Real scalars $$a, b, c, d$$, and quaternion $$z = a + bi + cj + dk$$ the following additional definitions apply:

• Conjugate of $$\mathit{z}$$ is $$z^{*} = a - bi - cj - dk$$
• Absolute value (magnitude) of $$\mathit{z}$$ is the non-negative Real scalar value

$\vert z \vert = (zz^{*})^{\frac{1}{2}} = \sqrt{a^{2} + b^{2} + c^{2} + d^{2}}$

• Multiplicative inverse (reciprocal) $$\mathit{z}$$ can be computed as

$\frac{1}{z} = \frac{z^{*}}{\vert z\vert^{2}} = \frac{z^{*}}{zz^{*}}$

• Given two distinct quaternions, $$q_1 = (a + \vec{u})$$ and $$q_2 = (b + \vec{v})$$, the product is not generally commutable and is defined as

$q_1 q_2 = (ab - \langle \vec{u}, \vec{v} \rangle) + (a\vec{v} + b\vec{u} + \vec{u} \times \vec{v})$

• Let $$z = \cos{(\frac{\alpha}{2})} + \sin{(\frac{\alpha}{2})}\vec{U}$$ be a unit quaternion. The mapping $$f(\vec{x}) = z\vec{x}z^{*}$$ is known as conjugation by $$\mathit{z},$$ where the vector $$\vec{x}$$ is considered a quaternion with its scalar component equal to zero. $$f(\vec{x})$$ rotates $$\vec{x}$$ counterclockwise through an angle $$\alpha$$ about an axis $$\vec{U}$$. The composition of two rotations corresponds to quaternion multiplication.

#include <quaternion.h>

## Public Member Functions

const bool operator!= (const quaternion &q) const

const quaternion operator* (const quaternion &q) const
quaternion multiplication (Grassmann Product) More...

const quaternion operator* (const scalar &s) const

const quaternion operator+ (const quaternion &q) const

const quaternion operator- (const quaternion &q) const

const quaternion operator/ (const scalar &s) const

const bool operator== (const quaternion &q) const

class construction and type conversion
quaternion ()

quaternion (const scalar &s, const vector3d &v)

quaternion (const scalar &q1, const scalar &q2, const scalar &q3, const scalar &q4)

class public methods

/**

const quaternion conjugate () const

const vector3d cross (const quaternion &q) const

const scalar dot (const quaternion &q) const
dot-product (Euclidean inner-product) More...

const scalar length () const
modulus (absolute value or length from origin) More...

void normalize ()

const quaternion unit () const

const scalarScalar () const

const vector3dVector () const

const quaternion sgn () const
Sign, sgn(z), of a complex number finds the complex number of the same direction found on the unit circle. More...

const scalar arg () const
Argument, arg(z), finds the angle of the 4-vector quaternion from the unit scalar (i.e. More...

class member operators
const quaternionoperator*= (const quaternion &q)

const quaternionoperator+= (const quaternion &q)

const quaternionoperator-= (const quaternion &q)

const quaternionoperator*= (const scalar &s)

const quaternionoperator/= (const scalar &s)

## Friends

const quaternion operator* (const scalar &s, const quaternion &q)

const quaternion operator- (const quaternion &q)

 math::quaternion::quaternion ( )
inline
 math::quaternion::quaternion ( const scalar & s, const vector3d & v )
inline
 math::quaternion::quaternion ( const scalar & q1, const scalar & q2, const scalar & q3, const scalar & q4 )
inline
 const scalar math::quaternion::arg ( ) const
inline

Argument, arg(z), finds the angle of the 4-vector quaternion from the unit scalar (i.e.

1).

 const quaternion math::quaternion::conjugate ( ) const
inline
 const vector3d math::quaternion::cross ( const quaternion & q ) const
inline
 const scalar math::quaternion::dot ( const quaternion & q ) const
inline

dot-product (Euclidean inner-product)

 const scalar math::quaternion::length ( ) const
inline

modulus (absolute value or length from origin)

 void math::quaternion::normalize ( )
inline
 const bool math::quaternion::operator!= ( const quaternion & q ) const
inline
 const quaternion math::quaternion::operator* ( const quaternion & q ) const
inline

quaternion multiplication (Grassmann Product)

 const quaternion math::quaternion::operator* ( const scalar & s ) const
inline
 const quaternion& math::quaternion::operator*= ( const quaternion & q )
inline
 const quaternion& math::quaternion::operator*= ( const scalar & s )
inline
 const quaternion math::quaternion::operator+ ( const quaternion & q ) const
inline
 const quaternion& math::quaternion::operator+= ( const quaternion & q )
inline
 const quaternion math::quaternion::operator- ( const quaternion & q ) const
inline
 const quaternion& math::quaternion::operator-= ( const quaternion & q )
inline
 const quaternion math::quaternion::operator/ ( const scalar & s ) const
inline
 const quaternion& math::quaternion::operator/= ( const scalar & s )
inline
 const bool math::quaternion::operator== ( const quaternion & q ) const
inline
 const scalar& math::quaternion::Scalar ( ) const
inline
 const quaternion math::quaternion::sgn ( ) const
inline

Sign, sgn(z), of a complex number finds the complex number of the same direction found on the unit circle.

 const quaternion math::quaternion::unit ( ) const
inline
 const vector3d& math::quaternion::Vector ( ) const
inline
 const quaternion operator* ( const scalar & s, const quaternion & q )
friend
 const quaternion operator- ( const quaternion & q )
friend