math::quaternion Class Reference

A quaternion. More...

#include <quaternion.h>

Collaboration diagram for math::quaternion:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 quaternion (void)
 Default Constructor.
 quaternion (const math::vector3 &v_, real_t w_)
 Constructor to set x y z w.
 quaternion (real_t x_, real_t y_, real_t z_, real_t w_)
 Constructor to set a x y z w.
 quaternion (const math::quaternion &p)
 Copy Constructor.
math::quaternionoperator= (const math::quaternion &p)
 Assignment Operator.
real_t w (void) const
 Returns a copy of w.
real_t x (void) const
 Returns a copy of x.
real_t y (void) const
 Returns a copy of y.
real_t z (void) const
 Returns a copy of z.
math::vector3 v (void) const
 Returns a copy of x y z.
math::vector3 vec (void) const
 Returns a copy of x y z.
real_t scalar (void) const
 Returns a copy of w.
void set (real_t x_, real_t y_, real_t z_, real_t w_)
 Sets the quaternion.
void set (const math::vector3 &v_, real_t w_)
 Sets the quaternion.
math::quaternion conjugate (void) const
 Returns the conjugate of the quaternion.
math::quaternion operator! (void) const
 Returns the inverse of the quaternion.
double magnitude (void) const
 Returns the magnitude of the quaternion.
void normalize (void)
 Normalizes the quaternion.
void set_identity (void)
 Sets the quaternion to the identity quaternion.
math::matrix4 get_rotation_matrix (void) const
 Returns the rotation matrix that describes this quaternion.
void get_rotation_matrix (math::matrix4 &m) const
 Sets a rotation matrix that describes this quaternion.
math::matrix4 get_transposed_rotation_matrix (void) const
 Returns the transposed rotation matrix that describes this quaternion.
void get_transposed_rotation_matrix (math::matrix4 &m) const
 Sets transposed rotation matrix that describes this quaternion.
math::quaternion operator* (const math::quaternion &rhs) const
 Quaternion Multiplication.
math::vector3 operator* (const math::vector3 &rhs) const
 Quaternion Vector Multiplication.
void from_angle_axis (real_t radians, const math::vector3 &axis)
 Creates a rotation matrix given around an arbitrary axis.
void get_angle_axis (real_t &radians, math::vector3 &axis) const
 Returns the angle and axis the quaternion describes.
void from_angles (real_t x_rad, real_t y_rad, real_t z_rad)
 Creates a unit length quaternion from three Euler angles.
void from_matrix3 (const real_t *mat)
 Creates a unit length quaternion from a 3x3 rotation matrix.
void from_matrix4 (const real_t *mat)
 Creates a unit length quaternion from a 4x4 rotation matrix.

Static Public Member Functions

static math::quaternion slerp (real_t percent, const math::quaternion &qa, math::quaternion qb)
 Spherical Linear Interpretation.

Static Public Attributes

static const math::quaternion IDENTITY
 The identity quaternion.

Friends

std::ostream & math::operator<< (std::ostream &o, const math::quaternion &vec)
 stream output operator.


Detailed Description

A quaternion.

Quaternions take on the form:

\[(x,y,z,w)\]

Note:
When sending the quaternion to OpenGL, use get_transposed_matrix().

Definition at line 46 of file quaternion.h.


Constructor & Destructor Documentation

math::quaternion::quaternion ( void   )  [inline]

Default Constructor.

Sets quaternion to $(0,0,0,1)$.

Definition at line 62 of file quaternion.h.

Referenced by conjugate(), operator!(), operator*(), and slerp().

math::quaternion::quaternion ( const math::vector3 v_,
real_t  w_ 
) [inline]

Constructor to set x y z w.

Parameters:
v_ vector which defines the quaternion's x y z.
w_ real_t which define the quaternion's w.

Definition at line 70 of file quaternion.h.

math::quaternion::quaternion ( real_t  x_,
real_t  y_,
real_t  z_,
real_t  w_ 
) [inline]

Constructor to set a x y z w.

Parameters:
x_ real_t which defines the quaternion's x.
y_ real_t which defines the quaternion's y.
z_ real_t which defines the quaternion's z.
w_ real_t which defines the quaternion's w.

Definition at line 80 of file quaternion.h.


Member Function Documentation

math::quaternion math::quaternion::conjugate ( void   )  const [inline]

Returns the conjugate of the quaternion.

The conjugate of the quaternion is defined as:

\[(x,y,z,-w)\]

Note:
Do data within quaternion is modified. A copy of the quaternion is returned.

Definition at line 170 of file quaternion.h.

References quaternion().

void math::quaternion::from_angle_axis ( real_t  radians,
const math::vector3 axis 
)

Creates a rotation matrix given around an arbitrary axis.

Given an axis and an angle, this method will create a set this quaternion as the quaternion that describes the rotation around the axis by angle.

Note:
Rotations are right-handed.
Parameters:
radians A real number in radians.
axis A unit length vector describing the axis to rotate around.

Definition at line 164 of file quaternion.cpp.

References math::equals(), and math::vector3::length().

Referenced by from_angles().

void math::quaternion::from_angles ( real_t  x_rad,
real_t  y_rad,
real_t  z_rad 
)

Creates a unit length quaternion from three Euler angles.

Parameters:
x_rad Rotation around x axis in radians.
y_rad Rotation around y axis in radians.
z_rad Rotation around z axis in radians.

Definition at line 203 of file quaternion.cpp.

References from_angle_axis(), normalize(), math::vector3::X_AXIS, math::vector3::Y_AXIS, and math::vector3::Z_AXIS.

void math::quaternion::from_matrix3 ( const real_t mat  ) 

Creates a unit length quaternion from a 3x3 rotation matrix.

Parameters:
mat Pointer to an real_t[ 9 ] representing a rotation matrix. Matrix is assumed to be stored in row major format.

Definition at line 221 of file quaternion.cpp.

References math::vector3::x(), math::vector3::y(), and math::vector3::z().

void math::quaternion::from_matrix4 ( const real_t mat  ) 

Creates a unit length quaternion from a 4x4 rotation matrix.

Parameters:
mat Pointer to an real_t[ 16 ] representing a rotation matrix. Matrix is assumed to be stored in row major format.

Definition at line 262 of file quaternion.cpp.

References math::vector3::x(), math::vector3::y(), and math::vector3::z().

void math::quaternion::get_angle_axis ( real_t radians,
math::vector3 axis 
) const

Returns the angle and axis the quaternion describes.

Parameters:
radians The angle about axis in radians (output).
axis The axis the quaternion's rotation is aroiund (output).
Returns:
Sets radians and axis.

Definition at line 176 of file quaternion.cpp.

References math::equals(), magnitude(), math::vector3::set(), math::vector3::x(), math::vector3::y(), and math::vector3::z().

void math::quaternion::get_rotation_matrix ( math::matrix4 m  )  const

Sets a rotation matrix that describes this quaternion.

Parameters:
m A matrix4 where the rotation matrix will be written.

Definition at line 37 of file quaternion.cpp.

References math::matrix4::set(), math::vector3::x(), math::vector3::y(), and math::vector3::z().

math::matrix4 math::quaternion::get_rotation_matrix ( void   )  const

Returns the rotation matrix that describes this quaternion.

Returns:
A matrix4 that describes the rotation this quaternion represents.

Definition at line 78 of file quaternion.cpp.

Referenced by operator*().

void math::quaternion::get_transposed_rotation_matrix ( math::matrix4 m  )  const

Sets transposed rotation matrix that describes this quaternion.

Parameters:
m A matrix4 where the rotation matrix will be written.
Note:
Use this method to send the quaternion to OpenGL functions such as glMultMatrix().

Definition at line 87 of file quaternion.cpp.

References math::matrix4::set(), math::vector3::x(), math::vector3::y(), and math::vector3::z().

math::matrix4 math::quaternion::get_transposed_rotation_matrix ( void   )  const

Returns the transposed rotation matrix that describes this quaternion.

Note:
Use this method to send the quaternion to OpenGL functions such as glMultMatrix().
Returns:
A transposed matrix4 that describes the rotation this quaternion represents.

Definition at line 128 of file quaternion.cpp.

double math::quaternion::magnitude ( void   )  const [inline]

Returns the magnitude of the quaternion.

The magnitude of the quaternion is defined as:

\[\sqrt{x^2+y^2+z^2+w^2}\]

Definition at line 190 of file quaternion.h.

Referenced by get_angle_axis(), and normalize().

void math::quaternion::normalize ( void   )  [inline]

Normalizes the quaternion.

Warning:
If the quaternion has zero magnitude, a divide by zero may be possible.

Definition at line 199 of file quaternion.h.

References magnitude(), math::vector3::x(), math::vector3::y(), and math::vector3::z().

Referenced by from_angles().

math::quaternion math::quaternion::operator! ( void   )  const [inline]

Returns the inverse of the quaternion.

The inverse of a normalized quaternion is defined as:

\[(x,y,z,-w)\]

Note:
Assumes the quaternion is normalized. No normalization check is performed.

Definition at line 180 of file quaternion.h.

References quaternion().

math::vector3 math::quaternion::operator* ( const math::vector3 rhs  )  const

Quaternion Vector Multiplication.

Multiplies the matrix that this quaternion describes by the vector rhs.

Definition at line 154 of file quaternion.cpp.

References get_rotation_matrix().

real_t math::quaternion::scalar ( void   )  const [inline]

Returns a copy of w.

See also:
w

Definition at line 137 of file quaternion.h.

void math::quaternion::set ( const math::vector3 v_,
real_t  w_ 
) [inline]

Sets the quaternion.

Parameters:
v_ vector which defines the quaternion's x y z.
w_ real_t which define the quaternion's w.

Definition at line 159 of file quaternion.h.

void math::quaternion::set ( real_t  x_,
real_t  y_,
real_t  z_,
real_t  w_ 
) [inline]

Sets the quaternion.

Parameters:
x_ real_t which defines the quaternion's x.
y_ real_t which defines the quaternion's y.
z_ real_t which defines the quaternion's z.
w_ real_t which defines the quaternion's w.

Definition at line 148 of file quaternion.h.

References math::vector3::set().

void math::quaternion::set_identity ( void   )  [inline]

Sets the quaternion to the identity quaternion.

The identity quaternion is defined as:

\[(0,0,0,1)\]

Definition at line 213 of file quaternion.h.

References math::vector3::set().

math::quaternion math::quaternion::slerp ( real_t  percent,
const math::quaternion qa,
math::quaternion  qb 
) [static]

Spherical Linear Interpretation.

Interprets the between the two rotations that qa and qb describe.

Parameters:
percent A real_t between [0-1] descibing how much to interpret between qa and qb.
qa Initial orientation.
qb Ending orientation.

Definition at line 301 of file quaternion.cpp.

References math::equals(), m_v, m_w, math::vector3::negate(), quaternion(), v(), w(), x(), y(), and z().

math::vector3 math::quaternion::v ( void   )  const [inline]

Returns a copy of x y z.

See also:
vec
Returns:
A vector containing x y z.

Definition at line 120 of file quaternion.h.

Referenced by slerp().

math::vector3 math::quaternion::vec ( void   )  const [inline]

Returns a copy of x y z.

See also:
v
Returns:
A vector containing x y z.

Definition at line 129 of file quaternion.h.

Referenced by fob::bird::get_quaternion().


Friends And Related Function Documentation

std::ostream& math::operator<< ( std::ostream &  o,
const math::quaternion vec 
) [friend]

stream output operator.

Outputs quaternion as x y z w.


Member Data Documentation

The identity quaternion.

The identity quaternion is described as:

\[(0,0,0,1)\]

Definition at line 321 of file quaternion.h.


Generated on Sat Feb 21 16:38:11 2009 for Flock of Birds Library by  doxygen 1.5.7.1