wfmath 1.0.3
A math library for the Worldforge system.
WFMath::Quaternion Class Reference

A normalized quaternion. More...

#include <quaternion.h>

Classes

class  Identity
 

Public Member Functions

 Quaternion (const Identity &)
 
 Quaternion ()
 Construct a Quaternion. More...
 
 Quaternion (CoordType w_in, CoordType x_in, CoordType y_in, CoordType z_in)
 Construct a Quaternion from (w, x, y, z) components. More...
 
 Quaternion (int axis, CoordType angle)
 Construct a Quaternion giving a rotation around axis by angle. More...
 
 Quaternion (const Vector< 3 > &axis, CoordType angle)
 Construct a Quaternion giving a rotation around the Vector axis by angle. More...
 
 Quaternion (const Vector< 3 > &axis)
 Construct a Quaternion giving a rotation around the Vector axis. More...
 
 Quaternion (const Quaternion &p)=default
 Construct a copy of a Quaternion. More...
 
 Quaternion (const AtlasInType &a)
 Construct a Quaternion from an Atlas::Message::Object. More...
 
AtlasOutType toAtlas () const
 Create an Atlas object from the Quaternion. More...
 
void fromAtlas (const AtlasInType &a)
 Set the Quaternion's value to that given by an Atlas object. More...
 
Quaternionoperator= (const Quaternion &rhs)=default
 
bool isEqualTo (const Quaternion &q, CoordType epsilon=numeric_constants< CoordType >::epsilon()) const
 
bool operator== (const Quaternion &rhs) const
 
bool operator!= (const Quaternion &rhs) const
 
bool isValid () const
 
Quaternionidentity ()
 Set the Quaternion to the identity rotation. More...
 
Quaternionoperator*= (const Quaternion &rhs)
 
Quaternionoperator/= (const Quaternion &rhs)
 
Quaternion operator* (const Quaternion &rhs) const
 
Quaternion operator/ (const Quaternion &rhs) const
 
bool fromRotMatrix (const RotMatrix< 3 > &m)
 set a Quaternion's value from a RotMatrix More...
 
Quaternion inverse () const
 returns the inverse of the Quaternion More...
 
Quaternionrotate (const RotMatrix< 3 > &)
 Rotate quaternion using the matrix. More...
 
Quaternionrotate (const Quaternion &q)
 rotate the quaternion using another quaternion More...
 
Quaternionrotation (int axis, CoordType angle)
 sets the Quaternion to a rotation by angle around axis More...
 
Quaternionrotation (const Vector< 3 > &axis, CoordType angle)
 sets the Quaternion to a rotation by angle around the Vector axis More...
 
Quaternionrotation (const Vector< 3 > &axis)
 sets the Quaternion to a rotation around the Vector axis More...
 
Quaternionrotation (const Vector< 3 > &from, const Vector< 3 > &to)
 Sets the Quaternion to rotate 'from' to be parallel to 'to'. More...
 
Quaternionrotation (const Vector< 3 > &from, const Vector< 3 > &to, const Vector< 3 > &fallbackAxis)
 Sets the Quaternion to rotate 'from' to be parallel to 'to'. More...
 
CoordType scalar () const
 returns the scalar (w) part of the Quaternion More...
 
const Vector< 3 > & vector () const
 returns the Vector (x, y, z) part of the quaternion More...
 
void normalize ()
 normalize to remove accumulated round-off error More...
 
unsigned age () const
 current round-off age More...
 

Static Public Member Functions

static const QuaternionIDENTITY ()
 

Friends

std::ostream & operator<< (std::ostream &os, const Quaternion &p)
 
std::istream & operator>> (std::istream &is, Quaternion &p)
 

Detailed Description

A normalized quaternion.

Definition at line 35 of file quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/8]

WFMath::Quaternion::Quaternion ( const Identity )
inline

Definition at line 48 of file quaternion.h.

◆ Quaternion() [2/8]

WFMath::Quaternion::Quaternion ( )
inline

Construct a Quaternion.

Definition at line 51 of file quaternion.h.

Referenced by IDENTITY().

◆ Quaternion() [3/8]

WFMath::Quaternion::Quaternion ( CoordType  w_in,
CoordType  x_in,
CoordType  y_in,
CoordType  z_in 
)

Construct a Quaternion from (w, x, y, z) components.

This normalizes the components so the sum of their squares is one.

Definition at line 49 of file quaternion.cpp.

References WFMath::Vector< dim >::setValid().

◆ Quaternion() [4/8]

WFMath::Quaternion::Quaternion ( int  axis,
CoordType  angle 
)
inline

Construct a Quaternion giving a rotation around axis by angle.

Definition at line 58 of file quaternion.h.

References rotation().

◆ Quaternion() [5/8]

WFMath::Quaternion::Quaternion ( const Vector< 3 > &  axis,
CoordType  angle 
)
inline

Construct a Quaternion giving a rotation around the Vector axis by angle.

Definition at line 62 of file quaternion.h.

References rotation().

◆ Quaternion() [6/8]

WFMath::Quaternion::Quaternion ( const Vector< 3 > &  axis)
inlineexplicit

Construct a Quaternion giving a rotation around the Vector axis.

The angle of rotating is equal to the magnitude of the Vector

Definition at line 70 of file quaternion.h.

References rotation().

◆ Quaternion() [7/8]

WFMath::Quaternion::Quaternion ( const Quaternion p)
default

Construct a copy of a Quaternion.

◆ Quaternion() [8/8]

WFMath::Quaternion::Quaternion ( const AtlasInType a)
inlineexplicit

Construct a Quaternion from an Atlas::Message::Object.

Definition at line 76 of file quaternion.h.

References fromAtlas().

Member Function Documentation

◆ age()

unsigned WFMath::Quaternion::age ( ) const
inline

current round-off age

Definition at line 187 of file quaternion.h.

◆ fromAtlas()

void WFMath::Quaternion::fromAtlas ( const AtlasInType a)
inline

Set the Quaternion's value to that given by an Atlas object.

Definition at line 127 of file atlasconv.h.

Referenced by Quaternion().

◆ fromRotMatrix()

bool WFMath::Quaternion::fromRotMatrix ( const RotMatrix< 3 > &  m)

set a Quaternion's value from a RotMatrix

Since a Quaternion can only represent an even-parity RotMatrix, this function returns false if the parity of m is odd. In this case, the quaternion is set to the value of m multiplied by a fixed parity-odd RotMatrix, so the full RotMatrix can be recovered by passing the Quaternion and the value of 'not_flip' returned by this function to RotMatrix::fromQuaternion().

Definition at line 138 of file quaternion.cpp.

References WFMath::RotMatrix< dim >::age(), WFMath::RotMatrix< dim >::elem(), WFMath::RotMatrix< dim >::parity(), WFMath::Prod(), WFMath::Vector< dim >::setValid(), and WFMath::RotMatrix< dim >::trace().

Referenced by rotate().

◆ IDENTITY()

const Quaternion & WFMath::Quaternion::IDENTITY ( )
static

Gets a static identity quaternion.

Returns
A static identity quaternion.

Definition at line 64 of file quaternion.cpp.

References Quaternion().

◆ identity()

Quaternion & WFMath::Quaternion::identity ( )
inline

Set the Quaternion to the identity rotation.

Definition at line 102 of file quaternion.h.

References WFMath::Vector< dim >::zero().

◆ inverse()

Quaternion WFMath::Quaternion::inverse ( ) const

returns the inverse of the Quaternion

Definition at line 189 of file quaternion.cpp.

◆ isEqualTo()

bool WFMath::Quaternion::isEqualTo ( const Quaternion q,
CoordType  epsilon = numeric_constants<CoordType>::epsilon() 
) const

Definition at line 75 of file quaternion.cpp.

◆ isValid()

bool WFMath::Quaternion::isValid ( ) const
inline

Definition at line 99 of file quaternion.h.

◆ normalize()

void WFMath::Quaternion::normalize ( )

normalize to remove accumulated round-off error

Definition at line 322 of file quaternion.cpp.

References WFMath::Vector< dim >::sqrMag().

◆ operator!=()

bool WFMath::Quaternion::operator!= ( const Quaternion rhs) const
inline

Definition at line 97 of file quaternion.h.

◆ operator*()

Quaternion WFMath::Quaternion::operator* ( const Quaternion rhs) const
inline

Definition at line 111 of file quaternion.h.

◆ operator*=()

Quaternion & WFMath::Quaternion::operator*= ( const Quaternion rhs)

Definition at line 112 of file quaternion.cpp.

◆ operator/()

Quaternion WFMath::Quaternion::operator/ ( const Quaternion rhs) const
inline

Definition at line 117 of file quaternion.h.

◆ operator/=()

Quaternion & WFMath::Quaternion::operator/= ( const Quaternion rhs)

Definition at line 125 of file quaternion.cpp.

◆ operator==()

bool WFMath::Quaternion::operator== ( const Quaternion rhs) const
inline

Definition at line 96 of file quaternion.h.

◆ rotate() [1/2]

Quaternion & WFMath::Quaternion::rotate ( const Quaternion q)
inline

rotate the quaternion using another quaternion

Definition at line 145 of file quaternion.h.

◆ rotate() [2/2]

Quaternion & WFMath::Quaternion::rotate ( const RotMatrix< 3 > &  m)

Rotate quaternion using the matrix.

Definition at line 198 of file quaternion.cpp.

References fromRotMatrix().

◆ rotation() [1/5]

Quaternion & WFMath::Quaternion::rotation ( const Vector< 3 > &  axis)

sets the Quaternion to a rotation around the Vector axis

The rotation angle is given by the magnitude of the Vector

Definition at line 247 of file quaternion.cpp.

References WFMath::Vector< dim >::mag().

◆ rotation() [2/5]

Quaternion & WFMath::Quaternion::rotation ( const Vector< 3 > &  axis,
CoordType  angle 
)

sets the Quaternion to a rotation by angle around the Vector axis

Definition at line 228 of file quaternion.cpp.

References WFMath::Vector< dim >::mag().

◆ rotation() [3/5]

Quaternion & WFMath::Quaternion::rotation ( const Vector< 3 > &  from,
const Vector< 3 > &  to 
)

Sets the Quaternion to rotate 'from' to be parallel to 'to'.

Parameters
fromThe vector to rotate from.
toThe vector to rotate to.

If the vectors are colinear a ColinearVectors exception is thrown. If this is undesirable see rotation(const Vector<3>&, const Vector<3>&, const Vector<3>&) instead

Definition at line 266 of file quaternion.cpp.

References WFMath::Cross(), and WFMath::Vector< dim >::sqrMag().

◆ rotation() [4/5]

Quaternion & WFMath::Quaternion::rotation ( const Vector< 3 > &  from,
const Vector< 3 > &  to,
const Vector< 3 > &  fallbackAxis 
)

Sets the Quaternion to rotate 'from' to be parallel to 'to'.

Parameters
fromThe vector to rotate from.
toThe vector to rotate to.
fallbackAxisIf the vectors are colinear, rotate around this axis instead.

Definition at line 294 of file quaternion.cpp.

References WFMath::Cross(), rotation(), and WFMath::Vector< dim >::sqrMag().

◆ rotation() [5/5]

Quaternion & WFMath::Quaternion::rotation ( int  axis,
CoordType  angle 
)

sets the Quaternion to a rotation by angle around axis

Definition at line 207 of file quaternion.cpp.

References WFMath::Vector< dim >::setValid().

Referenced by Quaternion(), and rotation().

◆ scalar()

CoordType WFMath::Quaternion::scalar ( ) const
inline

returns the scalar (w) part of the Quaternion

Definition at line 180 of file quaternion.h.

◆ toAtlas()

AtlasOutType WFMath::Quaternion::toAtlas ( ) const
inline

Create an Atlas object from the Quaternion.

Definition at line 172 of file atlasconv.h.

◆ vector()

const Vector< 3 > & WFMath::Quaternion::vector ( ) const
inline

returns the Vector (x, y, z) part of the quaternion

Definition at line 182 of file quaternion.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Quaternion p 
)
friend

Definition at line 325 of file stream.cpp.

◆ operator>>

std::istream & operator>> ( std::istream &  is,
Quaternion p 
)
friend

Definition at line 330 of file stream.cpp.


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