OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

ot::MathUtils Class Reference

#include <MathUtils.h>

Inheritance diagram for ot::MathUtils:

Inheritance graph
[legend]
List of all members.

Public Types

typedef double Matrix3x3 [3][3]
typedef double Matrix4x4 [4][4]
typedef double Vector3 [3]
typedef double Quaternion [4]
 XYX = 0 + 4 + 0
 XYZ = 0 + 4 + 2
 XZX = 0 + 8 + 0
 XZY = 0 + 8 + 1
 YXY = 16 + 0 + 1
 YXZ = 16 + 0 + 2
 YZX = 16 + 8 + 0
 YZY = 16 + 8 + 1
 ZXY = 32 + 0 + 1
 ZXZ = 32 + 0 + 2
 ZYX = 32 + 4 + 0
 ZYZ = 32 + 4 + 2
enum  EULER {
  XYX = 0 + 4 + 0, XYZ = 0 + 4 + 2, XZX = 0 + 8 + 0, XZY = 0 + 8 + 1,
  YXY = 16 + 0 + 1, YXZ = 16 + 0 + 2, YZX = 16 + 8 + 0, YZY = 16 + 8 + 1,
  ZXY = 32 + 0 + 1, ZXZ = 32 + 0 + 2, ZYX = 32 + 4 + 0, ZYZ = 32 + 4 + 2
}

Static Public Member Functions

static float * axisAngleToQuaternion (const float *axisa, float *qResult)
static std::vector< float > & axisAngleToQuaternion (const std::vector< float > &axisa, std::vector< float > &qResult)
static double * axisAngleToQuaternion (const double *axisa, Quaternion qResult)
static float * eulerToQuaternion (const float roll, const float pitch, const float yaw, float *qResult)
static std::vector< float > & eulerToQuaternion (const float roll, const float pitch, const float yaw, std::vector< float > &qResult)
static float * eulerToQuaternion (const double alpha, const double beta, const double gamma, const enum MathUtils::EULER sequence, float *qResult)
static float * invertQuaternion (const float *q, float *qResult)
static std::vector< float > & invertQuaternion (const std::vector< float > &q, std::vector< float > &qResult)
static float * matrixToQuaternion (const float matrix[3][3], float *qResult)
static std::vector< float > & matrixToQuaternion (const float matrix[3][3], std::vector< float > &qResult)
static float * multiplyQuaternion (const float *q1, const float *q2, float *qResult)
static std::vector< float > & multiplyQuaternion (const std::vector< float > &q1, const std::vector< float > &q2, std::vector< float > &qResult)
static double * multiplyQuaternion (const Quaternion q1, const Quaternion q2, Quaternion qResult)
static float * normalizeQuaternion (float *q)
static std::vector< float > & normalizeQuaternion (std::vector< float > &q)
static double * normalizeQuaternion (Quaternion q)
static float * rotateVector (const float *q, const float *v, float *vResult)
static std::vector< float > & rotateVector (const std::vector< float > &q, const std::vector< float > &v, std::vector< float > &vResult)
static float determinant (const float matrix[3][3])
static float * quaternionToAxisAngle (const float *q, float *axisa)
static double angle (const float *v1, const float *v2, const int dim)
static double angle (const std::vector< float > &v1, const std::vector< float > &v2, const int dim)
static double dot (const float *v1, const float *v2, const int dim)
static double dot (const std::vector< float > &v1, const std::vector< float > &v2, const int dim)
static float * slerp (const float *q1, const float *q2, const float t, float *qResult)
static std::vector< float > & slerp (const std::vector< float > &q1, const std::vector< float > &q2, const float t, std::vector< float > &qResult)
static void matrixMultiply (const Matrix4x4 m1, const Matrix4x4 m2, Matrix4x4 &m)
static void matrixMultiply (const Matrix3x3 m1, const Matrix3x3 m2, Matrix3x3 &m)
static void MatrixToEuler (Vector3 angles, const Matrix4x4 colMatrix)

Static Public Attributes

static const Matrix4x4 matrix4x4_flipY
static const Matrix4x4 matrix4x4_identity
static const double Pi = 3.1415926535897932385
static const double E = 2.7182818284590452354
static const double GradToRad = MathUtils::Pi / 180.0

Detailed Description

Definition at line 69 of file MathUtils.h.


Member Typedef Documentation

typedef double ot::MathUtils::Matrix3x3[3][3]

3x3 double matrix type

Definition at line 73 of file MathUtils.h.

typedef double ot::MathUtils::Matrix4x4[4][4]

4x4 double matrix type

Definition at line 75 of file MathUtils.h.

typedef double ot::MathUtils::Quaternion[4]

4 double vector used as quaternion

Definition at line 79 of file MathUtils.h.

typedef double ot::MathUtils::Vector3[3]

3 double vector

Reimplemented in ot::OTQtMath.

Definition at line 77 of file MathUtils.h.


Member Enumeration Documentation

encodes all possible euler angle sequences

Enumerator:
XYX 
XYZ 
XZX 
XZY 
YXY 
YXZ 
YZX 
YZY 
ZXY 
ZXZ 
ZYX 
ZYZ 

Definition at line 82 of file MathUtils.h.


Member Function Documentation

double ot::MathUtils::angle ( const std::vector< float > &  v1,
const std::vector< float > &  v2,
const int  dim 
) [static]

computes the angle between two n-dimensional vectors.

Parameters:
v1 vector<float> first vector
v2 vector<float> second vector
dim dimension n of the two vectors
Returns:
angle between the two vectors

Definition at line 423 of file MathUtils.cxx.

References angle(), and ot::copyV2A().

double ot::MathUtils::angle ( const float *  v1,
const float *  v2,
const int  dim 
) [static]

computes the angle between two n-dimensional vectors.

Parameters:
v1 float[n] first vector
v2 float[n] second vector
dim dimension n of the two vectors
Returns:
angle between the two vectors

Definition at line 394 of file MathUtils.cxx.

References dot(), and Pi.

Referenced by angle(), and ot::ThresholdFilterNode::onEventGenerated().

double * ot::MathUtils::axisAngleToQuaternion ( const double *  axisa,
Quaternion  qResult 
) [static]

converts an axis angle representation into a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
axisa double[4] containing axis and angle in radiants
qResult double[4] where the result is stored
Returns:
pointer to result array

Definition at line 119 of file MathUtils.cxx.

std::vector< float > & ot::MathUtils::axisAngleToQuaternion ( const std::vector< float > &  axisa,
std::vector< float > &  qResult 
) [static]

converts an axis angle representation into a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
axisa vector<float> (assumes length 4) containing axis and angle in radiants
qResult vector<float> (assumes length 4) where the result is stored
Returns:
reference to result vector

Definition at line 107 of file MathUtils.cxx.

References axisAngleToQuaternion(), ot::copyA2V(), and ot::copyV2A().

float * ot::MathUtils::axisAngleToQuaternion ( const float *  axisa,
float *  qResult 
) [static]

converts an axis angle representation into a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
axisa float[4] containing axis and angle in radiants
qResult float[4] where the result is stored
Returns:
pointer to result array

Definition at line 97 of file MathUtils.cxx.

Referenced by axisAngleToQuaternion(), ot::GPSGarminCompass::newData(), ot::GPSDirectionSource::newData(), and ot::CommonNodeFactory::parseRotation().

float ot::MathUtils::determinant ( const float  matrix[3][3]  )  [static]

computes the determinant of a 3x3 matrix.

Parameters:
matrix the 3x3 matrix to use
Returns:
determinant of the matrix

Definition at line 380 of file MathUtils.cxx.

Referenced by ot::CommonNodeFactory::parseRotation().

double ot::MathUtils::dot ( const std::vector< float > &  v1,
const std::vector< float > &  v2,
const int  dim 
) [static]

computes the dot product between two n-dimensional vectors.

Parameters:
v1 vector<float> first vector
v2 vector<float> second vector
dim dimension n of the two vectors
Returns:
dot product between the two vectors

Definition at line 641 of file MathUtils.cxx.

References ot::copyV2A(), and dot().

double ot::MathUtils::dot ( const float *  v1,
const float *  v2,
const int  dim 
) [static]

computes the dot product between two n-dimensional vectors.

Parameters:
v1 float[n] first vector
v2 float[n] second vector
dim dimension n of the two vectors
Returns:
dot product between the two vectors

Definition at line 630 of file MathUtils.cxx.

Referenced by angle(), dot(), and ot::FilterNode::onEventGenerated().

float * ot::MathUtils::eulerToQuaternion ( const double  alpha,
const double  beta,
const double  gamma,
const enum MathUtils::EULER  sequence,
float *  qResult 
) [static]

computes a quaternion from euler angles representing a rotation.

This is the general method and supports all euler angle sequences. Use this instead of the old one for more control.

Parameters:
alpha first euler angle
beta second euler angle
gamma third euler angle
sequence enum defining the sequence to use
qResult pointer to the result quaternion
Returns:
returns the pointer to the result quaternion

Definition at line 165 of file MathUtils.cxx.

References multiplyQuaternion().

std::vector< float > & ot::MathUtils::eulerToQuaternion ( const float  roll,
const float  pitch,
const float  yaw,
std::vector< float > &  qResult 
) [static]

computes a quaternion from euler angles representing a rotation.

Deprecated:
use the other overloaded variant instead.
Parameters:
roll rotation around looking axis
pitch rotation around up axis
yaw rotation around side axis
qResult vector<float> where the result is stored
Returns:
reference to result vector

Definition at line 155 of file MathUtils.cxx.

References ot::copyA2V(), and eulerToQuaternion().

float * ot::MathUtils::eulerToQuaternion ( const float  roll,
const float  pitch,
const float  yaw,
float *  qResult 
) [static]

computes a quaternion from euler angles representing a rotation.

Deprecated:
use the other overloaded variant instead.
Parameters:
roll rotation around looking axis
pitch rotation around up axis
yaw rotation around side axis
qResult float[4] where the result is stored
Returns:
pointer to result array

Definition at line 131 of file MathUtils.cxx.

Referenced by eulerToQuaternion(), ot::CommonNodeFactory::parseRotation(), ot::SpaceMouseModule::processMessages(), ot::P5GloveModule::pushEvent(), ot::InterSenseModule::pushEvent(), ot::QtMouseEventSinkBase::QtMouseEventSinkBase(), ot::MulticastInputModule::run(), ot::DynaSightModule::run(), and ot::ARToolKitPlusModule::updateEvent().

std::vector< float > & ot::MathUtils::invertQuaternion ( const std::vector< float > &  q,
std::vector< float > &  qResult 
) [static]

inverts a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q vector<float> (assumes length 4) storing the quaternion
qResult vector<float> where the result is stored
Returns:
reference to result vector

Definition at line 206 of file MathUtils.cxx.

References ot::copyA2V(), ot::copyV2A(), and invertQuaternion().

float * ot::MathUtils::invertQuaternion ( const float *  q,
float *  qResult 
) [static]

inverts a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q float[4] storing the quaternion
qResult float[4] where the result is stored
Returns:
pointer to result array

Definition at line 196 of file MathUtils.cxx.

Referenced by invertQuaternion(), ot::QtMouseEventSinkBase::isInsideOrientThreshCone(), rotateVector(), ot::OTQtMath::rotateVectorFromCSToCS(), and ot::InvertTransformation::transformEvent().

static void ot::MathUtils::matrixMultiply ( const Matrix3x3  m1,
const Matrix3x3  m2,
Matrix3x3 m 
) [static]

void ot::MathUtils::matrixMultiply ( const Matrix4x4  m1,
const Matrix4x4  m2,
Matrix4x4 m 
) [static]

Definition at line 529 of file MathUtils.cxx.

Referenced by ot::ARToolKitPlusModule::updateEvent().

void ot::MathUtils::MatrixToEuler ( Vector3  angles,
const Matrix4x4  colMatrix 
) [static]

Definition at line 565 of file MathUtils.cxx.

References Q_EPSILON.

Referenced by ot::ARToolKitPlusModule::updateEvent().

std::vector< float > & ot::MathUtils::matrixToQuaternion ( const float  matrix[3][3],
std::vector< float > &  qResult 
) [static]

converts a rotational matrix to a quaternion.

Parameters:
matrix float[3][3] storing the rotational matrix
qResult vector<float> where the result is stored
Returns:
reference to result vector

Definition at line 260 of file MathUtils.cxx.

References ot::copyA2V(), and matrixToQuaternion().

float * ot::MathUtils::matrixToQuaternion ( const float  matrix[3][3],
float *  qResult 
) [static]

converts a rotational matrix to a quaternion.

Parameters:
matrix float[3][3] storing the rotational matrix
qResult float[4] where the result is stored
Returns:
pointer to result array

Definition at line 220 of file MathUtils.cxx.

Referenced by ot::ARTDataTrackerModule::convert(), matrixToQuaternion(), ot::CommonNodeFactory::parseRotation(), and ot::ARToolKitPlusModule::updateEvent().

double * ot::MathUtils::multiplyQuaternion ( const Quaternion  q1,
const Quaternion  q2,
Quaternion  qResult 
) [static]

multiplies two quaternions and stores result in a third.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q1 Quaternion storing first quaternion
q2 Quaternion storing second quaternion
qResult Quaternion where the result is stored
Returns:
pointer to result array

Definition at line 293 of file MathUtils.cxx.

std::vector< float > & ot::MathUtils::multiplyQuaternion ( const std::vector< float > &  q1,
const std::vector< float > &  q2,
std::vector< float > &  qResult 
) [static]

multiplies two quaternions and stores result in a third.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q1 vector<float> (assumes length 4) storing first quaternion
q2 vector<float> (assumes length 4) storing second quaternion
qResult vector<float> where the result is stored
Returns:
pointer to result vector

Definition at line 279 of file MathUtils.cxx.

References ot::copyA2V(), ot::copyV2A(), and multiplyQuaternion().

float * ot::MathUtils::multiplyQuaternion ( const float *  q1,
const float *  q2,
float *  qResult 
) [static]

multiplies two quaternions and stores result in a third.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q1 float[4] storing first quaternion
q2 float[4] storing second quaternion
qResult float[4] where the result is stored
Returns:
pointer to result array

Definition at line 270 of file MathUtils.cxx.

Referenced by eulerToQuaternion(), ot::QtMouseEventSinkBase::isInsideOrientThreshCone(), multiplyQuaternion(), rotateVector(), ot::OTQtMath::rotateVectorFromCSToCS(), ot::VirtualTransformation::transformEvent(), and ot::StaticTransformation::transformEvent().

double * ot::MathUtils::normalizeQuaternion ( Quaternion  q  )  [static]

normalizes quaternion to unit length.

Here the computation is done in place and the parameter is changed !

Parameters:
q Quaternion storing quaternion
Returns:
pointer to result array

Definition at line 331 of file MathUtils.cxx.

std::vector< float > & ot::MathUtils::normalizeQuaternion ( std::vector< float > &  q  )  [static]

normalizes quaternion to unit length.

Here the computation is done in place and the parameter is changed !

Parameters:
q vector<float> (assumes length 4) storing quaternion
Returns:
reference to result vector

Definition at line 318 of file MathUtils.cxx.

References ot::copyA2V(), ot::copyV2A(), and normalizeQuaternion().

float * ot::MathUtils::normalizeQuaternion ( float *  q  )  [static]

normalizes quaternion to unit length.

Here the computation is done in place and the parameter is changed !

Parameters:
q float[4] storing quaternion
Returns:
pointer to result array

Definition at line 306 of file MathUtils.cxx.

Referenced by normalizeQuaternion(), ot::FilterNode::onEventGenerated(), ot::CommonNodeFactory::parseRotation(), ot::SpaceMouseModule::processMessages(), ot::TestSource::push(), ot::DynaSightModule::run(), and slerp().

static float* ot::MathUtils::quaternionToAxisAngle ( const float *  q,
float *  axisa 
) [static]

computes the vector and angle representation of a quaternion.

This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q float[4] storing the quaternion
axisa float[4] storing the vector and angle of the given quaternion
Returns:
pointer to result array (axisa)

std::vector< float > & ot::MathUtils::rotateVector ( const std::vector< float > &  q,
const std::vector< float > &  v,
std::vector< float > &  vResult 
) [static]

rotates a vector using a given unit quaternion.

It does not normalize the quaternion or check for unit length ! This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q vector<float> (assumes length 4) storing quaternion
v vector<float> (assumes length 3) storing vector
vResult vector<float> where the result is stored
Returns:
pointer to result array

Definition at line 364 of file MathUtils.cxx.

References ot::copyA2V(), ot::copyV2A(), and rotateVector().

float * ot::MathUtils::rotateVector ( const float *  q,
const float *  v,
float *  vResult 
) [static]

rotates a vector using a given unit quaternion.

It does not normalize the quaternion or check for unit length ! This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q float[4] storing quaternion
v float[3] storing vector
vResult float[3] where the result is stored
Returns:
pointer to result array

Definition at line 343 of file MathUtils.cxx.

References invertQuaternion(), and multiplyQuaternion().

Referenced by rotateVector(), ot::OTQtMath::rotateVectorFromCSToCS(), ot::VirtualTransformation::transformEvent(), ot::StaticTransformation::transformEvent(), and ot::InvertTransformation::transformEvent().

std::vector< float > & ot::MathUtils::slerp ( const std::vector< float > &  q1,
const std::vector< float > &  q2,
const float  t,
std::vector< float > &  qResult 
) [static]

computes the spherical linear interpolation between two quaternions.

The formulas used are probably only stable for t in [0,1], but it can be used to calculate extrapolations as well. Moreover the slerp is always computed on the shorter path between the quaternions. This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q1 vector<float> (assumes length 4) first quaternion
q2 vector<float> (assumes length 4) second quaternion
t interpolation parameter
qResult vector<float> stores result
Returns:
reference to result = qResult

Definition at line 514 of file MathUtils.cxx.

References ot::copyA2V(), ot::copyV2A(), and slerp().

float * ot::MathUtils::slerp ( const float *  q1,
const float *  q2,
const float  t,
float *  qResult 
) [static]

computes the spherical linear interpolation between two quaternions.

The formulas used are probably only stable for t in [0,1], but it can be used to calculate extrapolations as well. Moreover the slerp is always computed on the shorter path between the quaternions. This method operates directly on the arguments. Therefore using the same pointers for several arguments will produce wrong results !

Parameters:
q1 float[4] first quaternion
q2 float[4] second quaternion
t interpolation parameter
qResult float[4] stores result
Returns:
pointer to result = qResult

Definition at line 439 of file MathUtils.cxx.

References normalizeQuaternion().

Referenced by ot::ElasticFilterNode::push(), and slerp().


Member Data Documentation

const double ot::MathUtils::E = 2.7182818284590452354 [static]

the also nice constant e

Definition at line 341 of file MathUtils.h.

const double ot::MathUtils::GradToRad = MathUtils::Pi / 180.0 [static]

Initial value:

 {{1, 0, 0, 0},
                                                             {0,-1, 0, 0},
                                                             {0, 0, 1, 0},
                                                             {0, 0, 0, 1}}
mirror at the x-z-plane

Definition at line 313 of file MathUtils.h.

Referenced by ot::ARToolKitPlusModule::updateEvent().

Initial value:

 {{1, 0, 0, 0},
                                                                {0, 1, 0, 0},
                                                                {0, 0, 1, 0},
                                                                {0, 0, 0, 1}}
identity matrix

Definition at line 315 of file MathUtils.h.

const double ot::MathUtils::Pi = 3.1415926535897932385 [static]


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

copyright (c) 2006 Graz University of Technology