opensurgsim
Namespaces | Typedefs | Functions
Quaternion.h File Reference

Definitions of quaternion types. More...

#include <math.h>
#include <Eigen/Core>
#include <Eigen/Geometry>

Go to the source code of this file.

Namespaces

 SurgSim
 Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui needs glew but we need to call glewInit() from a osg callback, using this call we avoid getting warnings about redefinitions.
 

Typedefs

typedef Eigen::Quaternion< float > SurgSim::Math::Quaternionf
 A quaternion of floats. More...
 
typedef Eigen::Quaternion< double > SurgSim::Math::Quaterniond
 A quaternion of doubles. More...
 

Functions

template<typename T , int VOpt>
Eigen::Quaternion< T > SurgSim::Math::makeRotationQuaternion (const T &angle, const Eigen::Matrix< T, 3, 1, VOpt > &axis)
 Create a quaternion rotation corresponding to the specified angle (in radians) and axis. More...
 
template<typename T , int QOpt>
Eigen::Quaternion< T, QOpt > SurgSim::Math::negate (const Eigen::Quaternion< T, QOpt > &q)
 Quaternion negation (i.e. More...
 
template<typename T , int QOpt, int VOpt>
void SurgSim::Math::computeAngleAndAxis (const Eigen::Quaternion< T, QOpt > &quaternion, T *angle, Eigen::Matrix< T, 3, 1, VOpt > *axis)
 Get the angle (in radians) and axis corresponding to a quaternion's rotation. More...
 
template<typename T , int QOpt>
SurgSim::Math::computeAngle (const Eigen::Quaternion< T, QOpt > &quaternion)
 Get the angle corresponding to a quaternion's rotation, in radians. More...
 
template<typename T , int TOpt, int VOpt>
void SurgSim::Math::computeRotationVector (const Eigen::Transform< T, 3, Eigen::Isometry, TOpt > &end, const Eigen::Transform< T, 3, Eigen::Isometry, TOpt > &start, Eigen::Matrix< T, 3, 1, VOpt > *rotationVector)
 Get the vector corresponding to the rotation between transforms. More...
 
template<typename T , int QOpt>
Eigen::Quaternion< T, QOpt > SurgSim::Math::interpolate (const Eigen::Quaternion< T, QOpt > &q0, const Eigen::Quaternion< T, QOpt > &q1, T t)
 Interpolate (slerp) between 2 quaternions. More...
 
template<typename T >
::std::ostream & Eigen::operator<< (::std::ostream &os, const Eigen::Quaternion< T > &quaternion)
 

Detailed Description

Definitions of quaternion types.

Typedef Documentation

§ Quaterniond

typedef Eigen::Quaternion<double> SurgSim::Math::Quaterniond

A quaternion of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Quaternionf

typedef Eigen::Quaternion<float> SurgSim::Math::Quaternionf

A quaternion of floats.

This type (and any structs that contain it) can be safely allocated via new.

Function Documentation

§ computeAngle()

template<typename T , int QOpt>
T SurgSim::Math::computeAngle ( const Eigen::Quaternion< T, QOpt > &  quaternion)
inline

Get the angle corresponding to a quaternion's rotation, in radians.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
QOptthe option flags (alignment etc.) used for the quaternion argument. Can be deduced.
Parameters
quaternionthe rotation quaternion to inspect.
Returns
the angle of the rotation within [0 +pi], in radians.

§ computeAngleAndAxis()

template<typename T , int QOpt, int VOpt>
void SurgSim::Math::computeAngleAndAxis ( const Eigen::Quaternion< T, QOpt > &  quaternion,
T *  angle,
Eigen::Matrix< T, 3, 1, VOpt > *  axis 
)
inline

Get the angle (in radians) and axis corresponding to a quaternion's rotation.

Note
Unit quaternions cover the unit sphere twice (q=-q). To make sure that the same rotation (q or -q)
returns the same Axis/Angle, we need a pi range for the angle.
We choose to enforce half the angle in the quadrant [0 +pi/2], which leads to an output angle in [0 +pi].
Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
QOptthe option flags (alignment etc.) used for the quaternion argument. Can be deduced.
VOptthe option flags (alignment etc.) used for the axis vector argument. Can be deduced.
Parameters
quaternionthe rotation quaternion to inspect.
[out]anglethe angle of the rotation in [0 +pi], in radians.
[out]axisthe axis of the rotation.

§ computeRotationVector()

template<typename T , int TOpt, int VOpt>
void SurgSim::Math::computeRotationVector ( const Eigen::Transform< T, 3, Eigen::Isometry, TOpt > &  end,
const Eigen::Transform< T, 3, Eigen::Isometry, TOpt > &  start,
Eigen::Matrix< T, 3, 1, VOpt > *  rotationVector 
)

Get the vector corresponding to the rotation between transforms.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
TOptthe option flags (alignment etc.) used for the transform arguments. Can be deduced.
VOptthe option flags (alignment etc.) used for the vector argument. Can be deduced.
Parameters
endthe transform after the rotation.
startthe transform before the rotation.
[out]rotationVectora vector describing the rotation.

§ interpolate()

template<typename T , int QOpt>
Eigen::Quaternion<T, QOpt> SurgSim::Math::interpolate ( const Eigen::Quaternion< T, QOpt > &  q0,
const Eigen::Quaternion< T, QOpt > &  q1,
t 
)
inline

Interpolate (slerp) between 2 quaternions.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
QOptthe option flags (alignment etc.) used for the quaternion arguments. Can be deduced.
Parameters
q0The start quaternion (at time 0.0).
q1The end quaternion (at time 1.0).
tThe interpolation time requested. Within [0..1].
Returns
the quaternion resulting in the slerp interpolation at time t, between q0 and q1.
Note
t=0 => returns either q0 or -q0
t=1 => returns either q1 or -q1
'Interpolate' has been created because slerp might not be enough in certain cases. This gives room for correction and special future treatment

§ makeRotationQuaternion()

template<typename T , int VOpt>
Eigen::Quaternion<T> SurgSim::Math::makeRotationQuaternion ( const T &  angle,
const Eigen::Matrix< T, 3, 1, VOpt > &  axis 
)
inline

Create a quaternion rotation corresponding to the specified angle (in radians) and axis.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
VOptthe option flags (alignment etc.) used for the axis vector argument. Can be deduced.
Parameters
anglethe angle of the rotation, in radians.
axisthe axis of the rotation.
Returns
the rotation quaternion.

§ negate()

template<typename T , int QOpt>
Eigen::Quaternion<T, QOpt> SurgSim::Math::negate ( const Eigen::Quaternion< T, QOpt > &  q)
inline

Quaternion negation (i.e.

unary operator -)

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
QOptthe option flags (alignment etc.) used for the quaternion arguments. Can be deduced.
Parameters
qThe quaternion to negate
Returns
the negation of q (i.e. -q)