The OpenFOAM Foundation
quaternion Class Reference

Quaternion class used to perform rotations in 3D space. More...

Collaboration diagram for quaternion:

## Public Types

enum  rotationSequence {
ZYX , ZYZ , ZXY , ZXZ ,
YXZ , YXY , YZX , YZY ,
XYZ , XYX , XZY , XZX
}
Euler-angle rotation sequence. More...

typedef scalar cmptType
Component type. More...

## Public Member Functions

quaternion ()
Construct null. More...

quaternion (const scalar w, const vector &v)
Construct given scalar and vector parts. More...

quaternion (const vector &d, const scalar theta)
Construct a rotation quaternion given the direction d. More...

quaternion (const vector &d, const scalar cosTheta, const bool normalised)
Construct a rotation quaternion given the direction d. More...

quaternion (const scalar w)
Construct a real from the given scalar part, the vector part = zero. More...

quaternion (const vector &v)
Construct a pure imaginary quaternion given the vector part,. More...

quaternion (const rotationSequence rs, const vector &angles)
Construct a quaternion given the three Euler angles. More...

quaternion (const tensor &rotationTensor)
Construct a quaternion from a rotation tensor. More...

quaternion (Istream &)
Construct from Istream. More...

scalar w () const
Scalar part of the quaternion ( = cos(theta/2) for rotation) More...

const vectorv () const
Vector part of the quaternion ( = axis of rotation) More...

tensor R () const
The rotation tensor corresponding the quaternion. More...

vector eulerAngles (const rotationSequence rs) const
Return a vector of euler angles corresponding to the. More...

quaternion normalised () const

scalar & w ()
Scalar part of the quaternion ( = cos(theta/2) for rotation) More...

vectorv ()
Vector part of the quaternion ( = axis of rotation) More...

void normalise ()

vector transform (const vector &v) const
Rotate the given vector. More...

vector invTransform (const vector &v) const
Rotate the given vector anti-clockwise. More...

quaternion transform (const quaternion &q) const
Rotate the given quaternion (and normalise) More...

quaternion invTransform (const quaternion &q) const
Rotate the given quaternion anti-clockwise (and normalise) More...

void operator+= (const quaternion &)

void operator-= (const quaternion &)

void operator*= (const quaternion &)

void operator/= (const quaternion &)

void operator= (const scalar)

void operator= (const vector &)

void operator*= (const scalar)

void operator/= (const scalar)

## Static Public Member Functions

static quaternion unit (const vector &v)
Return the unit quaternion (versor) from the given vector. More...

## Static Public Attributes

static const direction rank = 1
Rank of quaternion is 1. More...

static const char *const typeName = "quaternion"

static const quaternion zero

static const quaternion I

## Friends

Istreamoperator>> (Istream &is, quaternion &)

Ostreamoperator<< (Ostream &os, const quaternion &C)

## Detailed Description

Quaternion class used to perform rotations in 3D space.

Source files

Definition at line 60 of file quaternion.H.

## ◆ cmptType

 typedef scalar cmptType

Component type.

Definition at line 98 of file quaternion.H.

## ◆ rotationSequence

 enum rotationSequence

Euler-angle rotation sequence.

Enumerator
ZYX
ZYZ
ZXY
ZXZ
YXZ
YXY
YZX
YZY
XYZ
XYX
XZY
XZX

Definition at line 101 of file quaternion.H.

## ◆ quaternion() [1/9]

 quaternion ( )
inline

Construct null.

Definition at line 28 of file quaternionI.H.

## ◆ quaternion() [2/9]

 quaternion ( const scalar w, const vector & v )
inline

Construct given scalar and vector parts.

Definition at line 32 of file quaternionI.H.

## ◆ quaternion() [3/9]

 quaternion ( const vector & d, const scalar theta )
inline

Construct a rotation quaternion given the direction d.

and angle theta

Definition at line 39 of file quaternionI.H.

## ◆ quaternion() [4/9]

 quaternion ( const vector & d, const scalar cosTheta, const bool normalised )
inline

Construct a rotation quaternion given the direction d.

and cosine angle cosTheta and a if d is normalised

Definition at line 46 of file quaternionI.H.

References Foam::mag(), Foam::normalised(), and Foam::sqrt().

Here is the call graph for this function:

## ◆ quaternion() [5/9]

 quaternion ( const scalar w )
inlineexplicit

Construct a real from the given scalar part, the vector part = zero.

Definition at line 67 of file quaternionI.H.

## ◆ quaternion() [6/9]

 quaternion ( const vector & v )
inlineexplicit

Construct a pure imaginary quaternion given the vector part,.

the scalar part = 0

Definition at line 74 of file quaternionI.H.

## ◆ quaternion() [7/9]

 quaternion ( const rotationSequence rs, const vector & angles )
inline

Construct a quaternion given the three Euler angles.

Definition at line 87 of file quaternionI.H.

Here is the call graph for this function:

## ◆ quaternion() [8/9]

 quaternion ( const tensor & rotationTensor )
inlineexplicit

Construct a quaternion from a rotation tensor.

Definition at line 175 of file quaternionI.H.

Here is the call graph for this function:

## ◆ quaternion() [9/9]

 quaternion ( Istream & is )

Construct from Istream.

Definition at line 38 of file quaternion.C.

## ◆ unit()

 Foam::quaternion unit ( const vector & v )
inlinestatic

Return the unit quaternion (versor) from the given vector.

(w = sqrt(1 - |sqr(v)|))

Definition at line 81 of file quaternionI.H.

References Foam::magSqr(), and Foam::sqrt().

Referenced by joint::unitQuaternion().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ w() [1/2]

 Foam::scalar w ( ) const
inline

Scalar part of the quaternion ( = cos(theta/2) for rotation)

Definition at line 254 of file quaternionI.H.

Here is the caller graph for this function:

## ◆ v() [1/2]

 const Foam::vector & v ( ) const
inline

Vector part of the quaternion ( = axis of rotation)

Definition at line 260 of file quaternionI.H.

Here is the caller graph for this function:

## ◆ R()

 Foam::tensor R ( ) const
inline

The rotation tensor corresponding the quaternion.

Definition at line 323 of file quaternionI.H.

References Foam::sqr(), w2, x, and y.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ eulerAngles()

 Foam::vector eulerAngles ( const rotationSequence rs ) const
inline

Return a vector of euler angles corresponding to the.

specified rotation sequence

Definition at line 372 of file quaternionI.H.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, Foam::sqr(), w2, x, y, and Foam::Zero.

Referenced by rigidBodyState::write(), and sixDoFRigidBodyState::write().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ normalised()

 Foam::quaternion normalised ( ) const
inline

Definition at line 278 of file quaternionI.H.

References Foam::mag().

Here is the call graph for this function:

## ◆ w() [2/2]

 Foam::scalar & w ( )
inline

Scalar part of the quaternion ( = cos(theta/2) for rotation)

Definition at line 266 of file quaternionI.H.

## ◆ v() [2/2]

 Foam::vector & v ( )
inline

Vector part of the quaternion ( = axis of rotation)

Definition at line 272 of file quaternionI.H.

## ◆ normalise()

 void normalise ( )
inline

Definition at line 284 of file quaternionI.H.

References Foam::mag().

Referenced by Foam::average().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ transform() [1/2]

 Foam::vector transform ( const vector & v ) const
inline

Rotate the given vector.

Definition at line 296 of file quaternionI.H.

References Foam::conjugate().

Referenced by searchableExtrudedCircle::findParametricNearest(), and septernion::operator/=().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ invTransform() [1/2]

 Foam::vector invTransform ( const vector & v ) const
inline

Rotate the given vector anti-clockwise.

Definition at line 302 of file quaternionI.H.

References Foam::conjugate().

Referenced by septernion::operator*=().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ transform() [2/2]

 Foam::quaternion transform ( const quaternion & q ) const
inline

Rotate the given quaternion (and normalise)

Definition at line 308 of file quaternionI.H.

References Foam::normalise().

Here is the call graph for this function:

## ◆ invTransform() [2/2]

 Foam::quaternion invTransform ( const quaternion & q ) const
inline

Rotate the given quaternion anti-clockwise (and normalise)

Definition at line 314 of file quaternionI.H.

References Foam::conjugate(), and Foam::normalise().

Here is the call graph for this function:

## ◆ operator+=()

 void operator+= ( const quaternion & q )
inline

Definition at line 526 of file quaternionI.H.

## ◆ operator-=()

 void operator-= ( const quaternion & q )
inline

Definition at line 532 of file quaternionI.H.

## ◆ operator*=() [1/2]

 void operator*= ( const quaternion & q )
inline

Definition at line 538 of file quaternionI.H.

References quaternion::v(), quaternion::w(), and w0.

Here is the call graph for this function:

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

 void operator/= ( const quaternion & q )
inline

Definition at line 545 of file quaternionI.H.

References Foam::inv().

Here is the call graph for this function:

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

 void operator= ( const scalar s )
inline

Definition at line 551 of file quaternionI.H.

References s().

Here is the call graph for this function:

## ◆ operator=() [2/2]

 void operator= ( const vector & v )
inline

Definition at line 557 of file quaternionI.H.

## ◆ operator*=() [2/2]

 void operator*= ( const scalar s )
inline

Definition at line 563 of file quaternionI.H.

References s().

Here is the call graph for this function:

## ◆ operator/=() [2/2]

 void operator/= ( const scalar s )
inline

Definition at line 569 of file quaternionI.H.

References s().

Here is the call graph for this function:

## ◆ operator>>

 Istream& operator>> ( Istream & is, quaternion & )
friend

## ◆ operator<<

 Ostream& operator<< ( Ostream & os, const quaternion & C )
friend

## ◆ rank

 const direction rank = 1
static

Rank of quaternion is 1.

Definition at line 110 of file quaternion.H.

## ◆ typeName

 const char *const typeName = "quaternion"
static

Definition at line 115 of file quaternion.H.

## ◆ zero

 const Foam::quaternion zero
static

Definition at line 117 of file quaternion.H.

## ◆ I

 const Foam::quaternion I
static

Definition at line 118 of file quaternion.H.

Referenced by septernion::operator=().

The documentation for this class was generated from the following files: