Ravelin
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
QUAT Class Reference

Quaternion class used for orientation. More...

#include <Quat.h>

Public Member Functions

 QUAT ()
 Default constructor. More...
 
 QUAT (REAL x, REAL y, REAL z, REAL w)
 Constructs a quaternion from four REAL values. More...
 
 QUAT (const QUAT &q)
 
 QUAT (const VECTORN &v)
 
 QUAT (const AANGLE &v)
 
 QUAT (const MATRIX3 &v)
 
bool unit () const
 Determines whether this is a unit quaternion.
 
void conjugate ()
 Negates the value of each of the x, y, and z coordinates in place.
 
void set_identity ()
 
void slerp (const QUAT &q, REAL alpha)
 Performs spherical linear interpolation between this and q. More...
 
void lerp (const QUAT &q, REAL alpha)
 Performs linear interpolation between this and q. More...
 
void to_rpy (REAL &roll, REAL &pitch, REAL &yaw) const
 Converts quaternion to roll/pitch/yaw.
 
void to_rpy (ORIGIN3 &RPY) const
 
QUATinvert ()
 Computes the inverse orientation represented by this quaternion in place.
 
QUAT inverse () const
 
REAL norm_sq () const
 Calculates the squared magnitude of a quaternion.
 
REAL norm () const
 
REAL norm_inf () const
 Returns the l-infinity norm of the quaternion components.
 
void normalize ()
 Normalizes this quaternion in place.
 
QUAToperator= (const VECTORN &v)
 Sets the quaternion based on the given parameters.
 
QUAToperator= (const AANGLE &a)
 Sets quaternion to that represented by an axis-angle representation.
 
QUAToperator= (const MATRIX3 &m)
 Converts a rotation matrix to a unit Quaternion.
 
QUAToperator= (const QUAT &q)
 Copy operator.
 
void calc_generalized_force (const VECTOR3 &t, REAL gt[4]) const
 
unsigned size () const
 
REAL & operator[] (unsigned i)
 Gets the i'th component of the quaternion. More...
 
const REAL & operator[] (unsigned i) const
 Gets the i'th component of the quaternion. More...
 
QUAT operator- (const QUAT &q) const
 Subtracts a quaternion from this
 
QUAToperator-= (const QUAT &q)
 Subtracts one quaternion from another.
 
QUAT operator+ (const QUAT &q) const
 Adds this quaternion to another and returns the result in a new quaternion.
 
QUAToperator+= (const QUAT &q)
 Adds this quaon to another and stores the result in this
 
QUAT operator* (const QUAT &q) const
 Multiplies this by q and returns the result.
 
QUAT operator/ (const QUAT &q) const
 Multiplies inv(q) by this and returns the result.
 
ORIGIN3 operator* (const ORIGIN3 &v) const
 Multiplies the 3x3 matrix corresponding to this quaternion by a 3D origin and returns the result in a new 3D origin.
 
QUAT operator* (REAL scalar) const
 Multiplies a quaternion by a scalar.
 
QUAT operator/ (REAL scalar) const
 
QUAToperator*= (const QUAT &q)
 Multiplies this by q and stores the result in this
 
QUAToperator*= (REAL scalar)
 Multiplies a quaternion by a scalar and stores the result in this
 
QUAToperator/= (REAL scalar)
 
REAL magnitude () const
 Calculates the magnitude of a quaternion.
 
VECTOR3 G_mult (REAL qx, REAL qy, REAL qz, REAL qw) const
 Multiplies the matrix 'G' by a quaternion vector. More...
 
QUAT G_transpose_mult (const VECTOR3 &v) const
 Multiplies the transpose of the matrix 'G' by a vector. More...
 
QUAT L_transpose_mult (const VECTOR3 &v) const
 Multiplies the transpose of the matrix 'L' by a vector. More...
 
VECTOR3 L_mult (REAL qx, REAL qy, REAL qz, REAL qw) const
 Multiplies the 3x4 matrix 'L' times a four dimensional array. More...
 

Static Public Member Functions

static bool rel_equal (const QUAT &q1, const QUAT &q2, REAL tol=-1.0)
 Determines whether two poses in 3D are relatively equivalent.
 
static QUAT zero ()
 Constructs a zero quaternion.
 
static QUAT conjugate (const QUAT &q)
 Negates the value of each of the x, y, and z coordinates of the given quaternion. More...
 
static QUAT identity ()
 
static QUAT slerp (const QUAT &q1, const QUAT &q2, REAL alpha)
 Performs spherical linear interpolation between this and q. More...
 
static QUAT lerp (const QUAT &q1, const QUAT &q2, REAL alpha)
 Performs non-spherical linear interpolation between this and q. More...
 
static QUAT rpy (REAL roll, REAL pitch, REAL yaw)
 Sets up the quaternion from roll-pitch-yaw. More...
 
static QUAT rpy (const ORIGIN3 &RPY)
 
static REAL calc_angle (const QUAT &q1, const QUAT &q2)
 Calculates the angle between two orientations.
 
static QUAT invert (const QUAT &q)
 Computes the inverse orientation of a quaternion.
 
static QUAT normalize (const QUAT &q)
 Computes the normalized quaternion of q.
 
static QUAT deriv (const QUAT &q, const VECTOR3 &w)
 Computes the derivative of a quaternion given current orientation and angular velocity. More...
 
static QUAT dderiv (const QUAT &q, const VECTOR3 &omega, const VECTOR3 &alpha)
 Calculates the second derivative of a quaternion. More...
 
static VECTOR3 to_omega (const QUAT &q, const QUAT &qd)
 Computes the angular velocity of a body given the current quaternion orientation and the quaternion velocity.
 

Public Attributes

REAL x
 First quaternion component.
 
REAL y
 Second quaternion component.
 
REAL z
 Third quaterion component.
 
REAL w
 Fourth quaternion component.
 

Detailed Description

Quaternion class used for orientation.

This class is used to represent orientation via unit quaternions. Note, however, that the user is responsible for normalizing the quaternions; normalization is not automatic.

Constructor & Destructor Documentation

QUAT::QUAT ( )

Default constructor.

Quaternion constructed as [0,0,0] 1

References w, x, y, and z.

Referenced by conjugate(), operator+(), and operator-().

QUAT::QUAT ( REAL  x,
REAL  y,
REAL  z,
REAL  w 
)

Constructs a quaternion from four REAL values.

Parameters
xthe first component of the vector
ythe second component of the vector
zthe third component of the vector
wthe scalar component of the quaternion

References w, x, y, and z.

Member Function Documentation

QUAT QUAT::conjugate ( const QUAT q)
static

Negates the value of each of the x, y, and z coordinates of the given quaternion.

Parameters
qthe quaternion from which the conjugate is to be computed

References QUAT(), w, x, y, and z.

QUAT QUAT::dderiv ( const QUAT q,
const VECTOR3 omega,
const VECTOR3 alpha 
)
static

Calculates the second derivative of a quaternion.

Note
alpha and omega are acceleration and velocity vectors in the global frame

References deriv().

QUAT QUAT::deriv ( const QUAT q,
const VECTOR3 w 
)
static

Computes the derivative of a quaternion given current orientation and angular velocity.

Note that the derivative is not generally a unit quaternion.

Parameters
qthe current orientation
wthe angular velocity (in the global frame) Uses the matrix: | -q.x +q.w -q.z +q.y | G = | -q.y +q.z +q.w -q.x | | -q.z -q.y +q.x +q.w |

References w, x, y, and z.

Referenced by dderiv(), and POSE3::operator+().

VECTOR3 QUAT::G_mult ( REAL  qx,
REAL  qy,
REAL  qz,
REAL  qw 
) const

Multiplies the matrix 'G' by a quaternion vector.

This matrix is used in the relationships omega = 2*G*qd and alpha = 2*G*qdd, where omega/alpha are the angular velocity/acceleration of a rigid body in the game frame and qd/qdd are the first/second time derivatives of the Euler (unit quaternion) parameters.

References w, x, y, and z.

Referenced by POSE3::qG_mult().

QUAT QUAT::G_transpose_mult ( const VECTOR3 v) const

Multiplies the transpose of the matrix 'G' by a vector.

This matrix is used in the relationships qd = 1/2*G^T*omega and qdd = 1/2*G^T*alpha - 1/4*omega^2*q, where omega/alpha are the angular velocity/acceleration of a rigid body in the global frame and qd/qdd are the first/second time derivatives of the Euler (unit quaternion) parameters.

References w, x, y, and z.

Referenced by POSE3::qG_transpose_mult().

VECTOR3 QUAT::L_mult ( REAL  qx,
REAL  qy,
REAL  qz,
REAL  qw 
) const

Multiplies the 3x4 matrix 'L' times a four dimensional array.

This matrix is used in the relationships omega' = 2*L*qd and alpha' = 2*L*qdd, where omega'/alpha' are the angular velocity/acceleration of a rigid body in the body's frame and qd/qdd are the first/second time derivatives of the Euler (unit quaternion) parameters.

The matrix L is defined as: -e1 e0 e3 -e2 -e2 -e3 e0 e1 -e3 e2 -e1 e0

References w, x, y, and z.

QUAT QUAT::L_transpose_mult ( const VECTOR3 v) const

Multiplies the transpose of the matrix 'L' by a vector.

This matrix is used in the relationships qd = 1/2*L^T*omega and qdd = 1/2*L^T*alpha' - 1/4*omega'^2*q, where omega'/alpha' are the angular velocity/acceleration of a rigid body in the body frame and qd/qdd are the first/second time derivatives of the Euler (unit quaternion) parameters.

The matrix L is defined as: -e1 e0 e3 -e2 -e2 -e3 e0 e1 -e3 e2 -e1 e0

References w, x, y, and z.

void QUAT::lerp ( const QUAT q,
REAL  alpha 
)

Performs linear interpolation between this and q.

Sets the orientation represented by this quaternion to a linear interpolated orientation between this and q. If alpha is 0, then *this is unaltered. If alpha is 1, then *this is set to q.

Parameters
qthe "final" orientation
alphainterpolation value (0 <= alpha <= 1)
QUAT QUAT::lerp ( const QUAT q1,
const QUAT q2,
REAL  alpha 
)
static

Performs non-spherical linear interpolation between this and q.

Calculates the orientation of determined by linear interpolation between q1 and q2. If alpha is 0, then q1 is returned. If alpha is 1, then q2 is returned.

Parameters
q1the "initial" orientation
q2the "final" orientation
alphainterpolation value (0 <= alpha <= 1)
Returns
the orientation linearly interpolated between q1 and q2

References normalize(), w, x, y, and z.

REAL & QUAT::operator[] ( unsigned  i)

Gets the i'th component of the quaternion.

Parameters
ifor i=0, returns the first component of the vector (x), for i=1, returns the second component of the vector (y), for i=2, returns the third component of the vector (z), for i=3, returns the scalar (w).

References w, x, y, and z.

const REAL & QUAT::operator[] ( unsigned  i) const

Gets the i'th component of the quaternion.

Parameters
ifor i=0, returns the first component of the vector (x), for i=1, returns the second component of the vector (y), for i=2, returns the third component of the vector (z), for i=3, returns the scalar (w).

References w, x, y, and z.

QUAT QUAT::rpy ( REAL  roll,
REAL  pitch,
REAL  yaw 
)
static

Sets up the quaternion from roll-pitch-yaw.

Parameters
rollthe rotation around the local x axis
pitchthe rotation around the local y axis
yawthe rotation around the local z axis

References w, x, y, and z.

void QUAT::slerp ( const QUAT q,
REAL  alpha 
)

Performs spherical linear interpolation between this and q.

Sets the orientation represented by this quaternion to a linear interpolated orientation between this and q. If alpha is 0, then *this is unaltered. If alpha is 1, then *this is set to q.

Parameters
qthe "final" orientation
alphainterpolation value (0 <= alpha <= 1)

Referenced by TRANSFORM3::interpolate_inverse_transform_point(), TRANSFORM3::interpolate_inverse_transform_vector(), TRANSFORM3::interpolate_transform_point(), POSE3::interpolate_transform_point(), TRANSFORM3::interpolate_transform_vector(), and POSE3::interpolate_transform_vector().

QUAT QUAT::slerp ( const QUAT q1,
const QUAT q2,
REAL  alpha 
)
static

Performs spherical linear interpolation between this and q.

Calculates the orientation of determined by linear interpolation between q1 and q2. If alpha is 0, then q1 is returned. If alpha is 1, then q2 is returned.

Parameters
q1the "initial" orientation
q2the "final" orientation
alphainterpolation value (0 <= alpha <= 1)
Returns
the orientation linearly interpolated between q1 and q2
Todo:
rewrite this function to avoid cancellation errors

References conjugate(), w, x, y, and z.


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