Ravelin
|
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 |
QUAT & | invert () |
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. | |
QUAT & | operator= (const VECTORN &v) |
Sets the quaternion based on the given parameters. | |
QUAT & | operator= (const AANGLE &a) |
Sets quaternion to that represented by an axis-angle representation. | |
QUAT & | operator= (const MATRIX3 &m) |
Converts a rotation matrix to a unit Quaternion. | |
QUAT & | operator= (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 | |
QUAT & | operator-= (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. | |
QUAT & | operator+= (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 |
QUAT & | operator*= (const QUAT &q) |
Multiplies this by q and stores the result in this | |
QUAT & | operator*= (REAL scalar) |
Multiplies a quaternion by a scalar and stores the result in this | |
QUAT & | operator/= (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. | |
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.
QUAT::QUAT | ( | ) |
Default constructor.
Quaternion constructed as [0,0,0] 1
Referenced by conjugate(), operator+(), and operator-().
QUAT::QUAT | ( | REAL | x, |
REAL | y, | ||
REAL | z, | ||
REAL | w | ||
) |
Calculates the second derivative of a quaternion.
References deriv().
Computes the derivative of a quaternion given current orientation and angular velocity.
Note that the derivative is not generally a unit quaternion.
q | the current orientation |
w | the 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 | |
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.
Referenced by POSE3::qG_mult().
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.
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
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
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.
q | the "final" orientation |
alpha | interpolation value (0 <= alpha <= 1) |
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.
q1 | the "initial" orientation |
q2 | the "final" orientation |
alpha | interpolation value (0 <= alpha <= 1) |
References normalize(), w, x, y, and z.
REAL & QUAT::operator[] | ( | unsigned | i | ) |
const REAL & QUAT::operator[] | ( | unsigned | i | ) | const |
|
static |
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.
q | the "final" orientation |
alpha | interpolation 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().
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.
q1 | the "initial" orientation |
q2 | the "final" orientation |
alpha | interpolation value (0 <= alpha <= 1) |
References conjugate(), w, x, y, and z.