Simple quaternion representation. More...
#include <quaternion.h>
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. | |
Quaternion & | operator+= (const Quaternion &q) |
Performs addition of the quaternions. | |
Quaternion | operator+ (const Quaternion &q) const |
Performs addition of the quaternions. | |
Quaternion & | operator-= (const Quaternion &q) |
Performs subtraction of the quaternions. | |
Quaternion | operator- (const Quaternion &q) const |
Performs subtraction of the quaternions. | |
Quaternion & | operator*= (const Quaternion &q) |
Performs mulitiplication of the quaternions. | |
Quaternion | operator* (const Quaternion &q) const |
Performs mulitiplication of the quaternions. | |
Quaternion & | operator*= (const Point3D &p) |
Performs mulitiplication with point. | |
Quaternion | operator* (const Point3D &p) const |
Performs mulitiplication with point. | |
Quaternion & | operator/= (const Quaternion &q) |
Performs division of the quaternions. | |
Quaternion | operator/ (const Quaternion &q) const |
Performs division of the quaternions. | |
Quaternion & | operator= (const Quaternion &q) |
Sets equal to. | |
Quaternion & | operator= (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). |
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.
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.
p | Euler angles. |
degrees | If 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.
x | Rotation around the X-axis in radians (roll [-PI, PI]). |
y | Rotation around the Y-axis in radians (pitch [-PI/2, PI/2]). |
z | Rotation 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.
axis | The axis for rotation. |
angle | The angle of rotation. |
degrees | If 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.
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] |
q | The quaternion to get the conjugate of. |
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.
x | Rotation around the X-axis (roll [-PI, PI]). |
y | Rotation around the Y-axis (pitch [-PI/2, PI/2]). |
z | Rotation around the Z-axis (yaw [-PI, PI]). |
degrees | If 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.
p | Euler angles. |
degrees | If 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.
degrees | If true, angles are provided in degrees, otherwise radians. |
Definition at line 346 of file quaternion.cpp.
void Quaternion::CreateFromEuler | ( | const Point3D & | p, |
bool | degrees = false |
||
) |
Creates the quaternion using Euler angles.
p | Euler angles. |
degrees | If 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.
x | Rotation around the X-axis (roll [-PI, PI]). |
y | Rotation around the Y-axis (pitch [-PI/2, PI/2]). |
z | Rotation around the Z-axis (yaw [-PI, PI]). (positive is clockwise). |
degrees | If 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.
axis | The axis for rotation. |
angle | The angle of rotation. |
degrees | If 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.
a | Quaternion 1. |
b | Quaternion 2. |
Definition at line 437 of file quaternion.cpp.
double Quaternion::Dot | ( | const Quaternion & | q ) | const |
Calculates dot product of quaternions.
q | The quaternion to calculate dot product with. |
Definition at line 421 of file quaternion.cpp.
Point3D Quaternion::GetAxis | ( | ) | const |
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] |
q | The quaternion to get the inverse of. |
Definition at line 544 of file quaternion.cpp.
double Quaternion::Norm | ( | const Quaternion & | q ) | [static] |
q | The quaternion to calculate norm for. |
Definition at line 406 of file quaternion.cpp.
double Quaternion::Norm | ( | ) | const |
Definition at line 393 of file quaternion.cpp.
Quaternion Quaternion::Normalize | ( | const Quaternion & | q ) | [static] |
Calculates normalized quaternion.
q | The quaternion to get the normalization of. |
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.
euler | If true than quaternion is converted to Euler angles for display. |
degrees | If 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.
q1 | The quaternion to rotate around. |
q2 | The quaternion rotating. |
Definition at line 603 of file quaternion.cpp.
Rotates the point.
p | The point to rotate. |
Definition at line 570 of file quaternion.cpp.
Rotates the point using the inverse of the quaternion.
p | The p to rotate with. |
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.
x | Rotation around X-axis (roll [-PI, PI]). |
degrees | If 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.
y | Rotation around Y-axis (pitch [-PI/2, PI/2]). |
degrees | If 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.
z | Rotation around Z-axis (yaw [-PI, PI]). |
degrees | If true the angle is in degrees, otherwise radians. |
Definition at line 247 of file quaternion.cpp.
double CxUtils::Quaternion::mW |
Real number scalar of quaternion.
Definition at line 121 of file quaternion.h.
double CxUtils::Quaternion::mX |
Part of vector (i).
Definition at line 122 of file quaternion.h.
double CxUtils::Quaternion::mY |
Part of vector (j).
Definition at line 123 of file quaternion.h.
double CxUtils::Quaternion::mZ |
Part of vector (k).
Definition at line 124 of file quaternion.h.