Public Member Functions | Static Public Member Functions | Public Attributes

CxUtils::Quaternion Class Reference

Simple quaternion representation. More...

#include <quaternion.h>

List of all members.

Public Member Functions

 Quaternion ()
 Constructor. Creates a Quaternion with 0 rotatation (1, 0, 0, 0).
 Quaternion (const Quaternion &q)
 Copy constructor.
 Quaternion (const Point3D &p, const bool degrees=false)
 Creates the quaternion using Euler angles.
 Quaternion (const double x, const double y, const double z)
 Creates the quaternion using Euler angles.
 Quaternion (const Point3D &axis, const double angle, bool degrees=false)
 Constructor. Initializes a rotation quatnerion given an axis and angle.
 Quaternion (const double w, const double x, const double y, const double z)
 Constructor.
void CreateRotation (const Point3D &axis, const double angle, bool degrees=false)
 Creates a rotation quaternion given an axis and angle.
void CreateFromEuler (const double x, const double y, const double z, bool degrees=false)
 Creates the quaternion using Euler angles.
void ConvertToEuler (double &x, double &y, double &z, bool degrees=false) const
 Converts the quaternion to Euler angles.
void CreateFromEuler (const Point3D &p, bool degrees=false)
 Creates the quaternion using Euler angles.
void ConvertToEuler (Point3D &p, bool degrees=false) const
 Converts the quaternion to Euler angles.
Point3D ConvertToEuler (bool degrees=false) const
 Converts the quaternion to Euler angles.
void SetRotationX (const double x, const bool degrees=false)
 Creates a rotation quaternion around the axis.
void SetRotationY (const double y, const bool degrees=false)
 Creates a rotation quaternion around the axis.
void SetRotationZ (const double z, const bool degrees=false)
 Creates a rotation quaternion around the axis.
void Clear ()
 Sets all values to 0.
void Print (const bool euler=false, const bool degrees=true) const
 Prints quaternion information to console.
double Norm () const
double Dot (const Quaternion &q) const
 Calculates dot product of quaternions.
Point3D GetAxis () const
Quaternion Normalize () const
 Normalizes the quaternion.
Quaternion Conjugate () const
 Converts the quaternion to its' conjugate.
Quaternion Invert () const
 Inverts the quaternion.
Point3D Rotate (const Point3D &p) const
 Rotates the point.
Point3D RotateInverse (const Point3D &p) const
 Rotates the point using the inverse of the quaternion.
Quaternionoperator+= (const Quaternion &q)
 Performs addition of the quaternions.
Quaternion operator+ (const Quaternion &q) const
 Performs addition of the quaternions.
Quaternionoperator-= (const Quaternion &q)
 Performs subtraction of the quaternions.
Quaternion operator- (const Quaternion &q) const
 Performs subtraction of the quaternions.
Quaternionoperator*= (const Quaternion &q)
 Performs mulitiplication of the quaternions.
Quaternion operator* (const Quaternion &q) const
 Performs mulitiplication of the quaternions.
Quaternionoperator*= (const Point3D &p)
 Performs mulitiplication with point.
Quaternion operator* (const Point3D &p) const
 Performs mulitiplication with point.
Quaternionoperator/= (const Quaternion &q)
 Performs division of the quaternions.
Quaternion operator/ (const Quaternion &q) const
 Performs division of the quaternions.
Quaternionoperator= (const Quaternion &q)
 Sets equal to.
Quaternionoperator= (const Point3D &p)
 Sets equal to.

Static Public Member Functions

static double Norm (const Quaternion &q)
static double Dot (const Quaternion &a, const Quaternion &b)
 Calculates dot product of quaternions.
static Quaternion Normalize (const Quaternion &q)
 Calculates normalized quaternion.
static Quaternion Conjugate (const Quaternion &q)
static Quaternion Invert (const Quaternion &q)
static Quaternion Rotate (const Quaternion &q1, const Quaternion &q2)
 Rotates the second quaternion over the first, and returns the resulting quaternion.

Public Attributes

double mW
 Real number scalar of quaternion.
double mX
 Part of vector (i).
double mY
 Part of vector (j).
double mZ
 Part of vector (k).

Detailed Description

Simple quaternion representation.

This quaternion data structure contains methods for most common operations involving quaternions including multiplication, division, rotation, etc.

Definition at line 58 of file quaternion.h.


Constructor & Destructor Documentation

Quaternion::Quaternion (  )

Constructor. Creates a Quaternion with 0 rotatation (1, 0, 0, 0).

Definition at line 64 of file quaternion.cpp.

Quaternion::Quaternion ( const Quaternion q )

Copy constructor.

Definition at line 76 of file quaternion.cpp.

Quaternion::Quaternion ( const Point3D p,
const bool  degrees = false 
)

Creates the quaternion using Euler angles.

Parameters:
pEuler angles.
degreesIf true angles are in degrees, otherwise radians.

Definition at line 153 of file quaternion.cpp.

Quaternion::Quaternion ( const double  x,
const double  y,
const double  z 
)

Creates the quaternion using Euler angles.

Parameters:
xRotation around the X-axis in radians (roll [-PI, PI]).
yRotation around the Y-axis in radians (pitch [-PI/2, PI/2]).
zRotation around the Z-axis in radians (yaw [-PI, PI]). Positive rotation is clockwise.

Definition at line 137 of file quaternion.cpp.

Quaternion::Quaternion ( const Point3D axis,
const double  angle,
bool  degrees = false 
)

Constructor. Initializes a rotation quatnerion given an axis and angle.

Parameters:
axisThe axis for rotation.
angleThe angle of rotation.
degreesIf true angle is in degrees, otherwise radians.

Definition at line 95 of file quaternion.cpp.

Quaternion::Quaternion ( const double  w,
const double  x,
const double  y,
const double  z 
)

Constructor.

Definition at line 115 of file quaternion.cpp.


Member Function Documentation

void Quaternion::Clear (  )

Sets all values to 0.

Definition at line 359 of file quaternion.cpp.

Quaternion Quaternion::Conjugate (  ) const

Converts the quaternion to its' conjugate.

Definition at line 498 of file quaternion.cpp.

Quaternion Quaternion::Conjugate ( const Quaternion q ) [static]
Parameters:
qThe quaternion to get the conjugate of.
Returns:
The conjugate of the quaternion.

Definition at line 511 of file quaternion.cpp.

void Quaternion::ConvertToEuler ( double &  x,
double &  y,
double &  z,
bool  degrees = false 
) const

Converts the quaternion to Euler angles.

Parameters:
xRotation around the X-axis (roll [-PI, PI]).
yRotation around the Y-axis (pitch [-PI/2, PI/2]).
zRotation around the Z-axis (yaw [-PI, PI]).
degreesIf true, angles are provided in degrees, otherwise radians.

Definition at line 300 of file quaternion.cpp.

void Quaternion::ConvertToEuler ( Point3D p,
bool  degrees = false 
) const

Converts the quaternion to Euler angles.

Parameters:
pEuler angles.
degreesIf true, angles are provided in degrees, otherwise radians.

Definition at line 331 of file quaternion.cpp.

Point3D Quaternion::ConvertToEuler ( bool  degrees = false ) const

Converts the quaternion to Euler angles.

Parameters:
degreesIf true, angles are provided in degrees, otherwise radians.
Returns:
Euler angles as a Point3D(x, y, z);

Definition at line 346 of file quaternion.cpp.

void Quaternion::CreateFromEuler ( const Point3D p,
bool  degrees = false 
)

Creates the quaternion using Euler angles.

Parameters:
pEuler angles.
degreesIf true angles are in degrees, otherwise radians.

Definition at line 232 of file quaternion.cpp.

void Quaternion::CreateFromEuler ( const double  x,
const double  y,
const double  z,
bool  degrees = false 
)

Creates the quaternion using Euler angles.

Parameters:
xRotation around the X-axis (roll [-PI, PI]).
yRotation around the Y-axis (pitch [-PI/2, PI/2]).
zRotation around the Z-axis (yaw [-PI, PI]). (positive is clockwise).
degreesIf true angles are in degrees, otherwise radians.

Definition at line 194 of file quaternion.cpp.

void Quaternion::CreateRotation ( const Point3D axis,
const double  angle,
bool  degrees = false 
)

Creates a rotation quaternion given an axis and angle.

Parameters:
axisThe axis for rotation.
angleThe angle of rotation.
degreesIf true angle is in degrees, otherwise radians.

Definition at line 169 of file quaternion.cpp.

double Quaternion::Dot ( const Quaternion a,
const Quaternion b 
) [static]

Calculates dot product of quaternions.

Parameters:
aQuaternion 1.
bQuaternion 2.
Returns:
Dot product of 2 quaternions.

Definition at line 437 of file quaternion.cpp.

double Quaternion::Dot ( const Quaternion q ) const

Calculates dot product of quaternions.

Parameters:
qThe quaternion to calculate dot product with.
Returns:
Dot product.

Definition at line 421 of file quaternion.cpp.

Point3D Quaternion::GetAxis (  ) const
Returns:
The Axis of the quaternion.

Definition at line 448 of file quaternion.cpp.

Quaternion Quaternion::Invert (  ) const

Inverts the quaternion.

Definition at line 527 of file quaternion.cpp.

Quaternion Quaternion::Invert ( const Quaternion q ) [static]
Parameters:
qThe quaternion to get the inverse of.
Returns:
The inverse of the quaternion.

Definition at line 544 of file quaternion.cpp.

double Quaternion::Norm ( const Quaternion q ) [static]
Parameters:
qThe quaternion to calculate norm for.
Returns:
Norm of the quaternion.

Definition at line 406 of file quaternion.cpp.

double Quaternion::Norm (  ) const
Returns:
Norm of the quaternion.

Definition at line 393 of file quaternion.cpp.

Quaternion Quaternion::Normalize ( const Quaternion q ) [static]

Calculates normalized quaternion.

Parameters:
qThe quaternion to get the normalization of.
Returns:
The normalized quaternion.

Definition at line 478 of file quaternion.cpp.

Quaternion Quaternion::Normalize (  ) const

Normalizes the quaternion.

Definition at line 459 of file quaternion.cpp.

Quaternion Quaternion::operator* ( const Point3D p ) const

Performs mulitiplication with point.

Definition at line 725 of file quaternion.cpp.

Quaternion Quaternion::operator* ( const Quaternion q ) const

Performs mulitiplication of the quaternions.

Definition at line 696 of file quaternion.cpp.

Quaternion & Quaternion::operator*= ( const Quaternion q )

Performs mulitiplication of the quaternions.

Definition at line 676 of file quaternion.cpp.

Quaternion & Quaternion::operator*= ( const Point3D p )

Performs mulitiplication with point.

Definition at line 712 of file quaternion.cpp.

Quaternion Quaternion::operator+ ( const Quaternion q ) const

Performs addition of the quaternions.

Definition at line 629 of file quaternion.cpp.

Quaternion & Quaternion::operator+= ( const Quaternion q )

Performs addition of the quaternions.

Definition at line 614 of file quaternion.cpp.

Quaternion Quaternion::operator- ( const Quaternion q ) const

Performs subtraction of the quaternions.

Definition at line 660 of file quaternion.cpp.

Quaternion & Quaternion::operator-= ( const Quaternion q )

Performs subtraction of the quaternions.

Definition at line 645 of file quaternion.cpp.

Quaternion Quaternion::operator/ ( const Quaternion q ) const

Performs division of the quaternions.

Definition at line 762 of file quaternion.cpp.

Quaternion & Quaternion::operator/= ( const Quaternion q )

Performs division of the quaternions.

Definition at line 737 of file quaternion.cpp.

Quaternion & Quaternion::operator= ( const Quaternion q )

Sets equal to.

Definition at line 782 of file quaternion.cpp.

Quaternion & Quaternion::operator= ( const Point3D p )

Sets equal to.

Definition at line 797 of file quaternion.cpp.

void Quaternion::Print ( const bool  euler = false,
const bool  degrees = true 
) const

Prints quaternion information to console.

Parameters:
eulerIf true than quaternion is converted to Euler angles for display.
degreesIf Euler angles are beingn displayed, set to true for degrees instead of radians.

Definition at line 375 of file quaternion.cpp.

Quaternion Quaternion::Rotate ( const Quaternion q1,
const Quaternion q2 
) [static]

Rotates the second quaternion over the first, and returns the resulting quaternion.

Parameters:
q1The quaternion to rotate around.
q2The quaternion rotating.
Returns:
The result of the rotation.

Definition at line 603 of file quaternion.cpp.

Point3D Quaternion::Rotate ( const Point3D p ) const

Rotates the point.

Parameters:
pThe point to rotate.
Returns:
The result of the rotation.

Definition at line 570 of file quaternion.cpp.

Point3D Quaternion::RotateInverse ( const Point3D p ) const

Rotates the point using the inverse of the quaternion.

Parameters:
pThe p to rotate with.
Returns:
The result of the rotation.

Definition at line 585 of file quaternion.cpp.

void Quaternion::SetRotationX ( const double  x,
const bool  degrees = false 
)

Creates a rotation quaternion around the axis.

Parameters:
xRotation around X-axis (roll [-PI, PI]).
degreesIf true the angle is in degrees, otherwise radians.

Definition at line 281 of file quaternion.cpp.

void Quaternion::SetRotationY ( const double  y,
const bool  degrees = false 
)

Creates a rotation quaternion around the axis.

Parameters:
yRotation around Y-axis (pitch [-PI/2, PI/2]).
degreesIf true the angle is in degrees, otherwise radians.

Definition at line 264 of file quaternion.cpp.

void Quaternion::SetRotationZ ( const double  z,
const bool  degrees = false 
)

Creates a rotation quaternion around the axis.

Parameters:
zRotation around Z-axis (yaw [-PI, PI]).
degreesIf true the angle is in degrees, otherwise radians.

Definition at line 247 of file quaternion.cpp.


Member Data Documentation

Real number scalar of quaternion.

Definition at line 121 of file quaternion.h.

Part of vector (i).

Definition at line 122 of file quaternion.h.

Part of vector (j).

Definition at line 123 of file quaternion.h.

Part of vector (k).

Definition at line 124 of file quaternion.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines