Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

fmat::QuaternionT< R > Class Template Reference

Quaternions can be more efficient and more stable for a series of rotations than a corresponding 3x3 matrix, also more compact storage. More...

#include <fmatSpatial.h>

Inheritance diagram for fmat::QuaternionT< R >:

Detailed Description

template<class R = fmatReal>
class fmat::QuaternionT< R >

Quaternions can be more efficient and more stable for a series of rotations than a corresponding 3x3 matrix, also more compact storage.

Definition at line 71 of file fmatSpatial.h.

List of all members.

Public Member Functions

 QuaternionT ()
 Default constructor, initialize to identity (0 rotation).
 QuaternionT (R w_, R x_, R y_, R z_)
 Explicit construction from elements (careful, does not check normalization!).
template<typename T >
QuaternionTimportFrom (const T &q)
 copies from another representation, assuming operator[] is supported and w is index 0
template<typename T >
exportTo () const
 copies into another representation, assuming operator[] is supported and w is index 0
template<typename T >
T & exportTo (T &q) const
 copies into another representation, assuming operator[] is supported and w is index 0
template<typename T >
void exportTo (T &w_, T &x_, T &y_, T &z_) const
 unpacks into specified storage
template<typename T >
void exportTo (T &x_, T &y_, T &z_) const
 unpacks into specified storage, skipping w which can be reconstitued from √(1-x^2-y^2-z^2), see fromAxis()
getW () const
 returns w
getX () const
 returns x
getY () const
 returns y
getZ () const
 returns z
bool operator== (const QuaternionT< R > &other) const
Matrix< 3, 3, R > toMatrix () const
 returns a 3x3 rotation matrix representation
 operator Matrix< 3, 3, R > () const
 allows conversion/assignment to Matrix<3,3>
Column< 3, R > axis () const
 return axis of rotation represented by quaternion q (i.e. the axis component of axis-angle representation)
angle () const
 Return angle of rotation (range ±π radians) about the quaternion's native axis (i.e. the angle component for axis-angle representation).
template<class T >
axisComponent (const T &v) const
 Return angle of rotation represented by the quaternion about an arbitrary axis (assumed to already be normalized).
fmat::Column< 3, R > ypr () const
 Returns yaw-pitch-roll aka heading-elevation-bank conversion, where roll-pitch-yaw correspond to compounding rotations about the global x, y, and z axis respectively (in that order).
QuaternionT inverse () const ATTR_must_check
 Negates just the quaternion axis.
template<typename Rb >
QuaternionT< typename
fmat_internal::promotion_trait
< R, Rb >::type > 
operator* (const QuaternionT< Rb > &q) const
 multiply quaternions
QuaternionT operator*= (const QuaternionT &q)
 multiply quaternions
template<template< size_t H, size_t W, typename Rt > class T, size_t W>
Matrix< 3, W, R > operator* (const T< 3, W, R > &m) const
 multiply 3-row matrix by quaternion
TransformT< R > operator* (const TransformT< R > &m) const
 multiply Transform by quaternion
Column< 3, R > operator* (const Column< 3, R > v) const
 multiply 3-element vector by quaternion
sumSq () const
 returns sum of squares of components; should be "close" to 1, otherwise call normalize()
norm () const
 returns magnitude of quaternion; should be "close" to 1, otherwise call normalize()
normalize ()
 Re-normalize the quaternion magnitude to 1 (or 0 if norm is already invalid) and positive W, returns the previous magnitude.

Static Public Member Functions

template<typename T >
static QuaternionT from (const T &q)
 copies from another representation, assuming operator[] is supported and w is index 0
static const QuaternionTidentity ()
 returns a no-op quaternion (0 rotation), the same as the default constructor, but can re-use this instance instead of creating new ones all the time
static QuaternionT< R > aboutX (R rad)
 generate quaternion representing rotation of rad radians about X axis
static QuaternionT< R > aboutY (R rad)
 generate quaternion representing rotation of rad radians about Y axis
static QuaternionT< R > aboutZ (R rad)
 generate quaternion representing rotation of rad radians about Z axis
template<class T >
static QuaternionT fromAxisAngle (const T &axis, R angle)
 Generate quaternion from axis-angle representation (angle in radians, axis will be re-normalized if non-zero angle).
template<class T >
static QuaternionT fromAxis (const T &axis)
 Generate quaternion from just the axis component of another quaternion (i.e. axis magnitude should be less than 1; 0 magnitude means no rotation).
template<class T >
static QuaternionT fromMatrix (const T &rot)
 Generate quaternion from rotation matrix, this assumes the rotation matrix is well-formed.

Static Public Attributes

static const QuaternionT IDENTITY
 identity instance

Protected Member Functions

 QuaternionT (const fmat_internal::NoInit &)
 no-op constructor for functions which fill in results with additional computation

Protected Attributes

w
x
y
z

Friends

std::ostream & operator<< (std::ostream &os, const QuaternionT< R > &q)

Constructor & Destructor Documentation

template<class R = fmatReal>
fmat::QuaternionT< R >::QuaternionT (  ) 

Default constructor, initialize to identity (0 rotation).

Definition at line 74 of file fmatSpatial.h.

Referenced by fmat::QuaternionT< R >::from(), fmat::QuaternionT< R >::fromAxis(), fmat::QuaternionT< R >::fromAxisAngle(), and fmat::QuaternionT< R >::inverse().

template<class R = fmatReal>
fmat::QuaternionT< R >::QuaternionT ( w_,
x_,
y_,
z_ 
)

Explicit construction from elements (careful, does not check normalization!).

Definition at line 77 of file fmatSpatial.h.

template<class R = fmatReal>
fmat::QuaternionT< R >::QuaternionT ( const fmat_internal::NoInit  )  [protected]

no-op constructor for functions which fill in results with additional computation

Definition at line 397 of file fmatSpatial.h.


Member Function Documentation

template<class R = fmatReal>
static QuaternionT<R> fmat::QuaternionT< R >::aboutX ( rad  )  [static]

generate quaternion representing rotation of rad radians about X axis

Definition at line 104 of file fmatSpatial.h.

Referenced by Grasper::checkGoalCandidate(), Grasper::PlanArmApproach::doStart(), IKCalliope::isSideGrasp(), and IKCalliope::solve().

template<class R = fmatReal>
static QuaternionT<R> fmat::QuaternionT< R >::aboutY ( rad  )  [static]

generate quaternion representing rotation of rad radians about Y axis

Definition at line 106 of file fmatSpatial.h.

Referenced by ArmController::ArmController(), and IKCalliope::solve().

template<class R = fmatReal>
static QuaternionT<R> fmat::QuaternionT< R >::aboutZ ( rad  )  [static]

generate quaternion representing rotation of rad radians about Z axis

Definition at line 108 of file fmatSpatial.h.

Referenced by CBracketGrasperPredicate< N >::admissible(), and IKCalliope::IKCalliope().

template<class R = fmatReal>
R fmat::QuaternionT< R >::angle (  )  const

Return angle of rotation (range ±π radians) about the quaternion's native axis (i.e. the angle component for axis-angle representation).

Handles some slight denormalization gracefully.

Definition at line 227 of file fmatSpatial.h.

Referenced by IKGradientSolver::step().

template<class R = fmatReal>
Column<3,R> fmat::QuaternionT< R >::axis (  )  const

return axis of rotation represented by quaternion q (i.e. the axis component of axis-angle representation)

Definition at line 217 of file fmatSpatial.h.

Referenced by IKGradientSolver::step().

template<class R = fmatReal>
template<class T >
R fmat::QuaternionT< R >::axisComponent ( const T &  v  )  const

Return angle of rotation represented by the quaternion about an arbitrary axis (assumed to already be normalized).

Definition at line 241 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename T >
void fmat::QuaternionT< R >::exportTo ( T &  x_,
T &  y_,
T &  z_ 
) const

unpacks into specified storage, skipping w which can be reconstitued from √(1-x^2-y^2-z^2), see fromAxis()

Definition at line 90 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename T >
void fmat::QuaternionT< R >::exportTo ( T &  w_,
T &  x_,
T &  y_,
T &  z_ 
) const

unpacks into specified storage

Definition at line 88 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename T >
T& fmat::QuaternionT< R >::exportTo ( T &  q  )  const

copies into another representation, assuming operator[] is supported and w is index 0

Definition at line 86 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename T >
T fmat::QuaternionT< R >::exportTo (  )  const

copies into another representation, assuming operator[] is supported and w is index 0

Definition at line 84 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename T >
static QuaternionT fmat::QuaternionT< R >::from ( const T &  q  )  [static]

copies from another representation, assuming operator[] is supported and w is index 0

Definition at line 80 of file fmatSpatial.h.

template<class R = fmatReal>
template<class T >
static QuaternionT fmat::QuaternionT< R >::fromAxis ( const T &  axis  )  [static]

Generate quaternion from just the axis component of another quaternion (i.e. axis magnitude should be less than 1; 0 magnitude means no rotation).

This method requires only basic operations on the input type, so you can pass a raw array or plist::Point...

Definition at line 126 of file fmatSpatial.h.

Referenced by LinkComponent::computeOwnAABB(), LinkComponent::getCollisionModelTransform(), LinkComponent::getModelTransform(), LinkComponent::getObstacle(), and IKCalliope::solve().

template<class R = fmatReal>
template<class T >
static QuaternionT fmat::QuaternionT< R >::fromAxisAngle ( const T &  axis,
angle 
) [static]

Generate quaternion from axis-angle representation (angle in radians, axis will be re-normalized if non-zero angle).

If axis is 0 length, initializes to identity (0 rotation)

Definition at line 113 of file fmatSpatial.h.

Referenced by IKSolver::Parallel::computeErrorGradient(), and GaitedFootsteps::expand().

template<class R = fmatReal>
template<class T >
static QuaternionT fmat::QuaternionT< R >::fromMatrix ( const T &  rot  )  [static]

Generate quaternion from rotation matrix, this assumes the rotation matrix is well-formed.

This implementation is based on cross pollination between "Angel"'s code on this page: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm and the Ogre3D Quaternion implementation, which itself references: Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes article "Quaternion Calculus and Fast Animation".

Definition at line 151 of file fmatSpatial.h.

Referenced by Grasper::computeGoalStates(), KinematicJoint::getQuaternion(), IKCalliope::IKCalliope(), and ShapeSpacePlanner3DR< N >::plotPath().

template<class R = fmatReal>
R fmat::QuaternionT< R >::getW (  )  const

returns w

Definition at line 92 of file fmatSpatial.h.

template<class R = fmatReal>
R fmat::QuaternionT< R >::getX (  )  const

returns x

Definition at line 93 of file fmatSpatial.h.

Referenced by MoCapLogger::gotMoCapGUI().

template<class R = fmatReal>
R fmat::QuaternionT< R >::getY (  )  const

returns y

Definition at line 94 of file fmatSpatial.h.

Referenced by MoCapLogger::gotMoCapGUI().

template<class R = fmatReal>
R fmat::QuaternionT< R >::getZ (  )  const

returns z

Definition at line 95 of file fmatSpatial.h.

Referenced by MoCapLogger::gotMoCapGUI().

template<class R = fmatReal>
static const QuaternionT& fmat::QuaternionT< R >::identity (  )  [static]

returns a no-op quaternion (0 rotation), the same as the default constructor, but can re-use this instance instead of creating new ones all the time

Definition at line 100 of file fmatSpatial.h.

Referenced by KinematicJoint::getQuaternion().

template<class R = fmatReal>
template<typename T >
QuaternionT& fmat::QuaternionT< R >::importFrom ( const T &  q  ) 

copies from another representation, assuming operator[] is supported and w is index 0

Definition at line 82 of file fmatSpatial.h.

template<class R = fmatReal>
QuaternionT fmat::QuaternionT< R >::inverse (  )  const

Negates just the quaternion axis.

Definition at line 279 of file fmatSpatial.h.

Referenced by fmat::crossProduct(), KinematicJoint::getQuaternion(), and fmat::invert().

template<class R = fmatReal>
R fmat::QuaternionT< R >::norm (  )  const

returns magnitude of quaternion; should be "close" to 1, otherwise call normalize()

Definition at line 364 of file fmatSpatial.h.

template<class R = fmatReal>
R fmat::QuaternionT< R >::normalize (  ) 

Re-normalize the quaternion magnitude to 1 (or 0 if norm is already invalid) and positive W, returns the previous magnitude.

Definition at line 367 of file fmatSpatial.h.

Referenced by IKGradientSolver::step().

template<class R = fmatReal>
fmat::QuaternionT< R >::operator Matrix< 3, 3, R > (  )  const

allows conversion/assignment to Matrix<3,3>

Definition at line 214 of file fmatSpatial.h.

template<class R = fmatReal>
Column<3,R> fmat::QuaternionT< R >::operator* ( const Column< 3, R >  v  )  const

multiply 3-element vector by quaternion

Definition at line 343 of file fmatSpatial.h.

template<class R = fmatReal>
TransformT<R> fmat::QuaternionT< R >::operator* ( const TransformT< R > &  m  )  const

multiply Transform by quaternion

Definition at line 323 of file fmatSpatial.h.

template<class R = fmatReal>
template<template< size_t H, size_t W, typename Rt > class T, size_t W>
Matrix<3,W,R> fmat::QuaternionT< R >::operator* ( const T< 3, W, R > &  m  )  const

multiply 3-row matrix by quaternion

Definition at line 303 of file fmatSpatial.h.

template<class R = fmatReal>
template<typename Rb >
QuaternionT<typename fmat_internal::promotion_trait<R,Rb>::type> fmat::QuaternionT< R >::operator* ( const QuaternionT< Rb > &  q  )  const

multiply quaternions

Definition at line 289 of file fmatSpatial.h.

template<class R = fmatReal>
QuaternionT fmat::QuaternionT< R >::operator*= ( const QuaternionT< R > &  q  ) 

multiply quaternions

Definition at line 299 of file fmatSpatial.h.

template<class R = fmatReal>
bool fmat::QuaternionT< R >::operator== ( const QuaternionT< R > &  other  )  const

Definition at line 97 of file fmatSpatial.h.

template<class R = fmatReal>
R fmat::QuaternionT< R >::sumSq (  )  const

returns sum of squares of components; should be "close" to 1, otherwise call normalize()

Definition at line 361 of file fmatSpatial.h.

Referenced by fmat::QuaternionT< R >::normalize().

template<class R = fmatReal>
Matrix<3,3,R> fmat::QuaternionT< R >::toMatrix (  )  const

returns a 3x3 rotation matrix representation

implemented by simplified version of operator*(*this, Matrix<3,3>::identity())

Definition at line 190 of file fmatSpatial.h.

Referenced by LinkComponent::getObstacle(), fmat::QuaternionT< R >::operator Matrix< 3, 3, R >(), and IKCalliope::solve().

template<class R = fmatReal>
fmat::Column<3,R> fmat::QuaternionT< R >::ypr (  )  const

Returns yaw-pitch-roll aka heading-elevation-bank conversion, where roll-pitch-yaw correspond to compounding rotations about the global x, y, and z axis respectively (in that order).

From the "driver's seat" positive heading is turning to the left (z is up, using right hand rule, not compass heading), positive pitch is looking down, and positive roll is spinning clockwise. Within this frame-oriented view, we apply rotation axes in the 'reverse' order: first z, then y, then x.

You can reconstruct a Quaternion from these values by: q · v = aboutZ(yaw) * aboutY(pitch) * aboutX(roll) · v Note we right-multiply v to apply the rotation, so x is applied to an incoming vector first, then y, then z.

With thanks to http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/ (note that page uses different axis mapping however!)

Definition at line 261 of file fmatSpatial.h.

Referenced by MoCapLogger::gotMoCapGUI(), IKCalliope::solve(), and fmat::ypr().


Friends And Related Function Documentation

template<class R = fmatReal>
std::ostream& operator<< ( std::ostream &  os,
const QuaternionT< R > &  q 
) [friend]

Definition at line 391 of file fmatSpatial.h.


Member Data Documentation

template<class R = fmatReal>
const QuaternionT< T > fmat::QuaternionT< T >::IDENTITY [static]

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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:23 2016 by Doxygen 1.6.3