Quaternion Class Reference

A quaternion class. More...

#include <math/gzmath.hh>

Public Member Functions

 Quaternion ()
 Default Constructor. More...
 
 Quaternion (const double &_w, const double &_x, const double &_y, const double &_z)
 Constructor. More...
 
 Quaternion (const double &_roll, const double &_pitch, const double &_yaw)
 Constructor from Euler angles in radians. More...
 
 Quaternion (const Vector3 &_axis, const double &_angle)
 Constructor from axis angle. More...
 
 Quaternion (const Vector3 &_rpy)
 Constructor. More...
 
 Quaternion (const Quaternion &_qt)
 Copy constructor. More...
 
 Quaternion (const ignition::math::Quaterniond &_qt)
 Copy constructor for ignition::math::Quaterniond. More...
 
 ~Quaternion ()
 Destructor. More...
 
void Correct ()
 Correct any nan values in this quaternion. More...
 
double Dot (const Quaternion &_q) const
 Dot product. More...
 
void GetAsAxis (Vector3 &_axis, double &_angle) const
 Return rotation as axis and angle. More...
 
Vector3 GetAsEuler () const
 Return the rotation in Euler angles. More...
 
Matrix3 GetAsMatrix3 () const
 Get the quaternion as a 3x3 matrix. More...
 
Matrix4 GetAsMatrix4 () const
 Get the quaternion as a 4x4 matrix. More...
 
Quaternion GetExp () const
 Return the exponent. More...
 
Quaternion GetInverse () const
 Get the inverse of this quaternion. More...
 
Quaternion GetLog () const
 Return the logarithm. More...
 
double GetPitch ()
 Get the Euler pitch angle in radians. More...
 
double GetRoll ()
 Get the Euler roll angle in radians. More...
 
Vector3 GetXAxis () const
 Return the X axis. More...
 
double GetYaw ()
 Get the Euler yaw angle in radians. More...
 
Vector3 GetYAxis () const
 Return the Y axis. More...
 
Vector3 GetZAxis () const
 Return the Z axis. More...
 
ignition::math::Quaterniond Ign () const
 Convert this quaternion to an ignition::math::Quaterniond. More...
 
Quaternion Integrate (const Vector3 &_angularVelocity, const double _deltaT) const
 Integrate quaternion for constant angular velocity vector along specified interval _deltaT. More...
 
void Invert ()
 Invert the quaternion. More...
 
bool IsFinite () const
 See if a quaternion is finite (e.g., not nan) More...
 
void Normalize ()
 Normalize the quaternion. More...
 
bool operator!= (const Quaternion &_qt) const
 Not equal to operator. More...
 
Quaternion operator* (const Quaternion &_q) const
 Multiplication operator. More...
 
Quaternion operator* (const double &_f) const
 Multiplication operator by a scalar. More...
 
Vector3 operator* (const Vector3 &_v) const
 Vector3 multiplication operator. More...
 
Quaternion operator*= (const Quaternion &qt)
 Multiplication operator. More...
 
Quaternion operator+ (const Quaternion &_qt) const
 Addition operator. More...
 
Quaternion operator+= (const Quaternion &_qt)
 Addition operator. More...
 
Quaternion operator- (const Quaternion &_qt) const
 Subtraction operator. More...
 
Quaternion operator- () const
 Unary minus operator. More...
 
Quaternion operator-= (const Quaternion &_qt)
 Subtraction operator. More...
 
Quaternionoperator= (const Quaternion &_qt)
 Equal operator. More...
 
Quaternionoperator= (const ignition::math::Quaterniond &_v)
 Assignment operator for ignition math. More...
 
bool operator== (const Quaternion &_qt) const
 Equal to operator. More...
 
Vector3 RotateVector (const Vector3 &_vec) const
 Rotate a vector using the quaternion. More...
 
Vector3 RotateVectorReverse (Vector3 _vec) const
 Do the reverse rotation of a vector by this quaternion. More...
 
void Round (int _precision)
 Round all values to _precision decimal places. More...
 
void Scale (double _scale)
 Scale a Quaternionion. More...
 
void Set (double _u, double _x, double _y, double _z)
 Set this quaternion from 4 floating numbers. More...
 
void SetFromAxis (double _x, double _y, double _z, double _a)
 Set the quaternion from an axis and angle. More...
 
void SetFromAxis (const Vector3 &_axis, double _a)
 Set the quaternion from an axis and angle. More...
 
void SetFromEuler (const Vector3 &_vec)
 Set the quaternion from Euler angles. More...
 
void SetFromEuler (double _roll, double _pitch, double _yaw)
 Set the quaternion from Euler angles. More...
 
void SetToIdentity ()
 Set the quaternion to the identity. More...
 

Static Public Member Functions

static Quaternion EulerToQuaternion (const Vector3 &_vec)
 Convert euler angles to a quaternion. More...
 
static Quaternion EulerToQuaternion (double _x, double _y, double _z)
 Convert euler angles to quatern. More...
 
static Quaternion Slerp (double _fT, const Quaternion &_rkP, const Quaternion &_rkQ, bool _shortestPath=false)
 Spherical linear interpolation between 2 quaternions, given the ends and an interpolation parameter between 0 and 1. More...
 
static Quaternion Squad (double _fT, const Quaternion &_rkP, const Quaternion &_rkA, const Quaternion &_rkB, const Quaternion &_rkQ, bool _shortestPath=false)
 Spherical quadratic interpolation given the ends and an interpolation parameter between 0 and 1. More...
 

Public Attributes

double w
 w value of the quaternion More...
 
double x
 x value of the quaternion More...
 
double y
 y value of the quaternion More...
 
double z
 z value of the quaternion More...
 

Friends

std::ostream & operator<< (std::ostream &_out, const gazebo::math::Quaternion &_q)
 Stream insertion operator. More...
 
std::istream & operator>> (std::istream &_in, gazebo::math::Quaternion &_q)
 Stream extraction operator. More...
 

Detailed Description

A quaternion class.

Constructor & Destructor Documentation

§ Quaternion() [1/7]

Default Constructor.

Referenced by Quaternion::operator*().

§ Quaternion() [2/7]

Quaternion ( const double &  _w,
const double &  _x,
const double &  _y,
const double &  _z 
)

Constructor.

Parameters
[in]_wW param
[in]_xX param
[in]_yY param
[in]_zZ param

§ Quaternion() [3/7]

Quaternion ( const double &  _roll,
const double &  _pitch,
const double &  _yaw 
)

Constructor from Euler angles in radians.

Parameters
[in]_rollroll
[in]_pitchpitch
[in]_yawyaw

§ Quaternion() [4/7]

Quaternion ( const Vector3 _axis,
const double &  _angle 
)

Constructor from axis angle.

Parameters
[in]_axisthe rotation axis
[in]_anglethe rotation angle in radians

§ Quaternion() [5/7]

Quaternion ( const Vector3 _rpy)

Constructor.

Parameters
[in]_rpyeuler angles

§ Quaternion() [6/7]

Quaternion ( const Quaternion _qt)

Copy constructor.

Parameters
[in]_qtQuaternion to copy

§ Quaternion() [7/7]

Quaternion ( const ignition::math::Quaterniond &  _qt)

Copy constructor for ignition::math::Quaterniond.

Parameters
[in]_qtIgnition math quaterniond to copy

§ ~Quaternion()

~Quaternion ( )

Destructor.

Member Function Documentation

§ Correct()

§ Dot()

double Dot ( const Quaternion _q) const

Dot product.

Parameters
[in]_qthe other quaternion
Returns
the product

Referenced by Quaternion::Correct().

§ EulerToQuaternion() [1/2]

static Quaternion EulerToQuaternion ( const Vector3 _vec)
static

Convert euler angles to a quaternion.

Parameters
[in]_vecThe vector of angles to convert.
Returns
The converted quaternion.

Referenced by Quaternion::GetInverse().

§ EulerToQuaternion() [2/2]

static Quaternion EulerToQuaternion ( double  _x,
double  _y,
double  _z 
)
static

Convert euler angles to quatern.

Parameters
[in]_xrotation along x
[in]_yrotation along y
[in]_zrotation along z
Returns
The converted quaternion.

§ GetAsAxis()

void GetAsAxis ( Vector3 _axis,
double &  _angle 
) const

Return rotation as axis and angle.

Parameters
[in]_axisrotation axis
[in]_angleccw angle in radians

Referenced by Quaternion::GetInverse().

§ GetAsEuler()

Vector3 GetAsEuler ( ) const

Return the rotation in Euler angles.

Returns
This quaternion as an Euler vector

Referenced by Quaternion::GetInverse().

§ GetAsMatrix3()

Matrix3 GetAsMatrix3 ( ) const

Get the quaternion as a 3x3 matrix.

Returns
The 3x3 matrix form of the quaternion

Referenced by Quaternion::Correct().

§ GetAsMatrix4()

Matrix4 GetAsMatrix4 ( ) const

Get the quaternion as a 4x4 matrix.

Returns
a 4x4 matrix

Referenced by Quaternion::Correct().

§ GetExp()

Quaternion GetExp ( ) const

Return the exponent.

Returns
the exp

Referenced by Quaternion::GetInverse().

§ GetInverse()

§ GetLog()

Quaternion GetLog ( ) const

Return the logarithm.

Returns
the log

Referenced by Quaternion::GetInverse().

§ GetPitch()

double GetPitch ( )

Get the Euler pitch angle in radians.

Returns
the pitch component

Referenced by Quaternion::GetInverse().

§ GetRoll()

double GetRoll ( )

Get the Euler roll angle in radians.

Returns
the roll component

Referenced by Quaternion::GetInverse().

§ GetXAxis()

Vector3 GetXAxis ( ) const

Return the X axis.

Returns
the X axis of the vector

Referenced by Quaternion::Correct().

§ GetYaw()

double GetYaw ( )

Get the Euler yaw angle in radians.

Returns
the yaw component

Referenced by Quaternion::GetInverse().

§ GetYAxis()

Vector3 GetYAxis ( ) const

Return the Y axis.

Returns
the Y axis of the vector

Referenced by Quaternion::Correct().

§ GetZAxis()

Vector3 GetZAxis ( ) const

Return the Z axis.

Returns
the Z axis of the vector

Referenced by Quaternion::Correct().

§ Ign()

ignition::math::Quaterniond Ign ( ) const

Convert this quaternion to an ignition::math::Quaterniond.

Returns
This quaternion as an ignition::math::Quaterniond.

§ Integrate()

Quaternion Integrate ( const Vector3 _angularVelocity,
const double  _deltaT 
) const

Integrate quaternion for constant angular velocity vector along specified interval _deltaT.

Parameters
[in]_angularVelocityAngular velocity vector, specified in same reference frame as base of this quaternion.
[in]_deltaTTime interval in seconds to integrate over.
Returns
Quaternion at integrated configuration.

Referenced by Quaternion::Correct().

§ Invert()

void Invert ( )

Invert the quaternion.

§ IsFinite()

bool IsFinite ( ) const

See if a quaternion is finite (e.g., not nan)

Returns
True if quaternion is finite

Referenced by Quaternion::RotateVector().

§ Normalize()

void Normalize ( )

Normalize the quaternion.

Referenced by Pose::CoordRotationSub(), and Quaternion::GetInverse().

§ operator!=()

bool operator!= ( const Quaternion _qt) const

Not equal to operator.

Parameters
[in]_qtQuaternion for comparison
Returns
True if not equal

Referenced by Quaternion::operator*().

§ operator*() [1/3]

Quaternion operator* ( const Quaternion _q) const
inline

Multiplication operator.

Parameters
[in]_qQuaternion for multiplication
Returns
This quaternion multiplied by the parameter

References Quaternion::operator!=(), Quaternion::operator*=(), Quaternion::operator-(), Quaternion::operator==(), Quaternion::Quaternion(), Quaternion::w, Quaternion::x, Quaternion::y, and Quaternion::z.

§ operator*() [2/3]

Quaternion operator* ( const double &  _f) const

Multiplication operator by a scalar.

Parameters
[in]_ffactor
Returns
quaternion multiplied by the scalar

§ operator*() [3/3]

Vector3 operator* ( const Vector3 _v) const

Vector3 multiplication operator.

Parameters
[in]_vvector to multiply
Returns
The result of the vector multiplication

§ operator*=()

Quaternion operator*= ( const Quaternion qt)

Multiplication operator.

Parameters
[in]_qtQuaternion for multiplication
Returns
This quaternion multiplied by the parameter

Referenced by Quaternion::operator*().

§ operator+()

Quaternion operator+ ( const Quaternion _qt) const

Addition operator.

Parameters
[in]_qtquaternion for addition
Returns
this quaternion + _qt

Referenced by Quaternion::GetInverse().

§ operator+=()

Quaternion operator+= ( const Quaternion _qt)

Addition operator.

Parameters
[in]_qtquaternion for addition
Returns
this quaternion + qt

Referenced by Quaternion::GetInverse().

§ operator-() [1/2]

Quaternion operator- ( const Quaternion _qt) const

Subtraction operator.

Parameters
[in]_qtquaternion to subtract
Returns
this quaternion - _qt

§ operator-() [2/2]

Quaternion operator- ( ) const

Unary minus operator.

Returns
negates each component of the quaternion

Referenced by Quaternion::GetInverse(), and Quaternion::operator*().

§ operator-=()

Quaternion operator-= ( const Quaternion _qt)

Subtraction operator.

Parameters
[in]_qtQuaternion for subtraction
Returns
This quaternion - qt

Referenced by Quaternion::GetInverse().

§ operator=() [1/2]

Quaternion& operator= ( const Quaternion _qt)

Equal operator.

Parameters
[in]_qtQuaternion to copy

§ operator=() [2/2]

Quaternion& operator= ( const ignition::math::Quaterniond &  _v)

Assignment operator for ignition math.

Parameters
[in]_va new value
Returns
The new quaternion.

§ operator==()

bool operator== ( const Quaternion _qt) const

Equal to operator.

Parameters
[in]_qtQuaternion for comparison
Returns
True if equal

Referenced by Quaternion::operator*().

§ RotateVector()

Vector3 RotateVector ( const Vector3 _vec) const
inline

Rotate a vector using the quaternion.

Parameters
[in]_vecvector to rotate
Returns
the rotated vector

References Quaternion::GetInverse(), Quaternion::IsFinite(), Quaternion::RotateVectorReverse(), Vector3::x, Quaternion::x, Vector3::y, Quaternion::y, Vector3::z, and Quaternion::z.

§ RotateVectorReverse()

Vector3 RotateVectorReverse ( Vector3  _vec) const

Do the reverse rotation of a vector by this quaternion.

Parameters
[in]_vecthe vector
Returns
the reversed vector

Referenced by Quaternion::RotateVector().

§ Round()

void Round ( int  _precision)

Round all values to _precision decimal places.

Parameters
[in]_precisionthe precision

Referenced by Quaternion::Correct().

§ Scale()

void Scale ( double  _scale)

Scale a Quaternionion.

Parameters
[in]_scaleAmount to scale this rotation

Referenced by Quaternion::GetInverse().

§ Set()

void Set ( double  _u,
double  _x,
double  _y,
double  _z 
)

Set this quaternion from 4 floating numbers.

Parameters
[in]_uu
[in]_xx
[in]_yy
[in]_zz

Referenced by Quaternion::GetInverse().

§ SetFromAxis() [1/2]

void SetFromAxis ( double  _x,
double  _y,
double  _z,
double  _a 
)

Set the quaternion from an axis and angle.

Parameters
[in]_xX axis
[in]_yY axis
[in]_zZ axis
[in]_aAngle in radians

Referenced by Quaternion::GetInverse().

§ SetFromAxis() [2/2]

void SetFromAxis ( const Vector3 _axis,
double  _a 
)

Set the quaternion from an axis and angle.

Parameters
[in]_axisAxis
[in]_aAngle in radians

§ SetFromEuler() [1/2]

void SetFromEuler ( const Vector3 _vec)

Set the quaternion from Euler angles.

The order of operations is roll, pitch, yaw around a fixed body frame axis (the original frame of the object before rotation is applied). Roll is a rotation about x, pitch is about y, yaw is about z.

Parameters
[in]_vecEuler angle

Referenced by Quaternion::GetInverse().

§ SetFromEuler() [2/2]

void SetFromEuler ( double  _roll,
double  _pitch,
double  _yaw 
)

Set the quaternion from Euler angles.

Parameters
[in]_rollRoll angle (radians).
[in]_pitchPitch angle (radians).
[in]_yawYaw angle (radians).

§ SetToIdentity()

void SetToIdentity ( )

Set the quaternion to the identity.

Referenced by Quaternion::GetInverse().

§ Slerp()

static Quaternion Slerp ( double  _fT,
const Quaternion _rkP,
const Quaternion _rkQ,
bool  _shortestPath = false 
)
static

Spherical linear interpolation between 2 quaternions, given the ends and an interpolation parameter between 0 and 1.

Parameters
[in]_ftthe interpolation parameter
[in]_rkPthe beginning quaternion
[in]_rkQthe end quaternion
[in]_shortestPathwhen true, the rotation may be inverted to get to minimize rotation
Returns
The result of the linear interpolation

Referenced by Quaternion::Correct(), and OnePoleQuaternion::Process().

§ Squad()

static Quaternion Squad ( double  _fT,
const Quaternion _rkP,
const Quaternion _rkA,
const Quaternion _rkB,
const Quaternion _rkQ,
bool  _shortestPath = false 
)
static

Spherical quadratic interpolation given the ends and an interpolation parameter between 0 and 1.

Parameters
[in]_ftthe interpolation parameter
[in]_rkPthe beginning quaternion
[in]_rkAfirst intermediate quaternion
[in]_rkBsecond intermediate quaternion
[in]_rkQthe end quaternion
[in]_shortestPathwhen true, the rotation may be inverted to get to minimize rotation
Returns
The result of the quadratic interpolation

Referenced by Quaternion::Correct().

Friends And Related Function Documentation

§ operator<<

std::ostream& operator<< ( std::ostream &  _out,
const gazebo::math::Quaternion _q 
)
friend

Stream insertion operator.

Parameters
[in]_outoutput stream
[in]_qquaternion to output
Returns
the stream

§ operator>>

std::istream& operator>> ( std::istream &  _in,
gazebo::math::Quaternion _q 
)
friend

Stream extraction operator.

Parameters
[in]_ininput stream
[in]_qQuaternion to read values into
Returns
The istream

Member Data Documentation

§ w

§ x

§ y

§ z


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