Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Quaternion< Scalar > Class Template Reference

The quaternion class used to represent 3D orientations and rotations. More...

Public Types

typedef AngleAxis< ScalarAngleAxisType
 
typedef Matrix< Scalar, 4, 1 > Coefficients
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef _Scalar Scalar
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
- Public Types inherited from RotationBase< Quaternion< _Scalar >, 3 >
enum  
 
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
 
typedef ei_traits< Quaternion
< _Scalar > >::Scalar 
Scalar
 

Public Member Functions

Scalar angularDistance (const Quaternion &other) const
 
template<typename NewScalarType >
ei_cast_return_type
< Quaternion, Quaternion
< NewScalarType > >::type 
cast () const
 
const Coefficientscoeffs () const
 
Coefficientscoeffs ()
 
Quaternion conjugate (void) const
 
Scalar dot (const Quaternion &other) const
 
Quaternion inverse (void) const
 
bool isApprox (const Quaternion &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
 
Scalar norm () const
 
void normalize ()
 
Quaternion normalized () const
 
Quaternion operator* (const Quaternion &q) const
 
template<typename Derived >
Vector3 operator* (const MatrixBase< Derived > &vec) const
 
template<typename Derived >
Quaternion< Scalar >::Vector3 operator* (const MatrixBase< Derived > &v) const
 
Quaternionoperator*= (const Quaternion &q)
 
Quaternionoperator= (const Quaternion &other)
 
Quaternionoperator= (const AngleAxisType &aa)
 
template<typename Derived >
Quaternionoperator= (const MatrixBase< Derived > &m)
 
template<typename Derived >
Quaternion< Scalar > & operator= (const MatrixBase< Derived > &xpr)
 
 Quaternion ()
 
 Quaternion (Scalar w, Scalar x, Scalar y, Scalar z)
 
 Quaternion (const Quaternion &other)
 
 Quaternion (const AngleAxisType &aa)
 
template<typename Derived >
 Quaternion (const MatrixBase< Derived > &other)
 
template<typename OtherScalarType >
 Quaternion (const Quaternion< OtherScalarType > &other)
 
template<typename Derived1 , typename Derived2 >
QuaternionsetFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
template<typename Derived1 , typename Derived2 >
Quaternion< Scalar > & setFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
QuaternionsetIdentity ()
 
Quaternion slerp (Scalar t, const Quaternion &other) const
 
Scalar squaredNorm () const
 
Matrix3 toRotationMatrix (void) const
 
const Block< Coefficients, 3, 1 > vec () const
 
Block< Coefficients, 3, 1 > vec ()
 
Scalar w () const
 
Scalarw ()
 
Scalar x () const
 
Scalarx ()
 
Scalar y () const
 
Scalary ()
 
Scalar z () const
 
Scalarz ()
 
- Public Member Functions inherited from RotationBase< Quaternion< _Scalar >, 3 >
const Quaternion< _Scalar > & derived () const
 
Quaternion< _Scalar > & derived ()
 
Quaternion< _Scalar > inverse () const
 
Transform< Scalar, Dim > operator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const Scaling< Scalar, Dim > &s) const
 
Transform< Scalar, Dim > operator* (const Transform< Scalar, Dim > &t) const
 
RotationMatrixType toRotationMatrix () const
 

Static Public Member Functions

static Quaternion Identity ()
 

Protected Attributes

Coefficients m_coeffs
 

Detailed Description

template<typename Scalar>
class Eigen::Quaternion< Scalar >

The quaternion class used to represent 3D orientations and rotations.

This is defined in the Geometry module.

#include <Eigen/Geometry>
Parameters
_Scalarthe scalar type, i.e., the type of the coefficients

This class represents a quaternion $ w+xi+yj+zk $ that is a convenient representation of orientations and rotations of objects in three dimensions. Compared to other representations like Euler angles or 3x3 matrices, quatertions offer the following advantages:

The following two typedefs are provided for convenience:

See Also
class AngleAxis, class Transform

Member Typedef Documentation

the equivalent angle-axis type

typedef Matrix<Scalar, 4, 1> Coefficients

the type of the Coefficients 4-vector

typedef Matrix<Scalar,3,3> Matrix3

the equivalent rotation matrix type

typedef _Scalar Scalar

the scalar type of the coefficients

typedef Matrix<Scalar,3,1> Vector3

the type of a 3D vector

Constructor & Destructor Documentation

Quaternion ( )
inline

Default constructor leaving the quaternion uninitialized.

Quaternion ( Scalar  w,
Scalar  x,
Scalar  y,
Scalar  z 
)
inline

Constructs and initializes the quaternion $ w+xi+yj+zk $ from its four coefficients w, x, y and z.

Warning
Note the order of the arguments: the real w coefficient first, while internally the coefficients are stored in the following order: [x, y, z, w]
Quaternion ( const Quaternion< Scalar > &  other)
inline

Copy constructor

Quaternion ( const AngleAxisType aa)
inlineexplicit

Constructs and initializes a quaternion from the angle-axis aa

Quaternion ( const MatrixBase< Derived > &  other)
inlineexplicit

Constructs and initializes a quaternion from either:

  • a rotation matrix expression,
  • a 4D vector expression representing quaternion coefficients.
    See Also
    operator=(MatrixBase<Derived>)
Quaternion ( const Quaternion< OtherScalarType > &  other)
inlineexplicit

Copy constructor with scalar type conversion

Member Function Documentation

Scalar angularDistance ( const Quaternion< Scalar > &  other) const
inline
Returns
the angle (in radian) between two rotations
See Also
dot()
ei_cast_return_type<Quaternion,Quaternion<NewScalarType> >::type cast ( ) const
inline
Returns
*this with scalar type casted to NewScalarType

Note that if NewScalarType is equal to the current scalar type of *this then this function smartly returns a const reference to *this.

const Coefficients& coeffs ( ) const
inline
Returns
a read-only vector expression of the coefficients (x,y,z,w)
Coefficients& coeffs ( )
inline
Returns
a vector expression of the coefficients (x,y,z,w)
Quaternion< Scalar > conjugate ( void  ) const
inline
Returns
the conjugate of the *this which is equal to the multiplicative inverse if the quaternion is normalized. The conjugate of a quaternion represents the opposite rotation.
See Also
Quaternion::inverse()
Scalar dot ( const Quaternion< Scalar > &  other) const
inline
Returns
the dot product of *this and other Geometrically speaking, the dot product of two unit quaternions corresponds to the cosine of half the angle between the two rotations.
See Also
angularDistance()
static Quaternion Identity ( )
inlinestatic
Returns
a quaternion representing an identity rotation
See Also
MatrixBase::Identity()
Quaternion< Scalar > inverse ( void  ) const
inline
Returns
the multiplicative inverse of *this Note that in most cases, i.e., if you simply want the opposite rotation, and/or the quaternion is normalized, then it is enough to use the conjugate.
See Also
Quaternion::conjugate()
bool isApprox ( const Quaternion< Scalar > &  other,
typename NumTraits< Scalar >::Real  prec = precision<Scalar>() 
) const
inline
Returns
true if *this is approximately equal to other, within the precision determined by prec.
See Also
MatrixBase::isApprox()
Scalar norm ( ) const
inline
Returns
the norm of the quaternion's coefficients
See Also
Quaternion::squaredNorm(), MatrixBase::norm()
void normalize ( )
inline

Normalizes the quaternion *this

See Also
normalized(), MatrixBase::normalize()
Quaternion normalized ( ) const
inline
Returns
a normalized version of *this
See Also
normalize(), MatrixBase::normalized()
Quaternion< Scalar > operator* ( const Quaternion< Scalar > &  other) const
inline
Returns
the concatenation of two rotations as a quaternion-quaternion product
Quaternion<Scalar>::Vector3 operator* ( const MatrixBase< Derived > &  v) const
inline

Rotation of a vector by a quaternion.

Remarks
If the quaternion is used to rotate several points (>1) then it is much more efficient to first convert it to a 3x3 Matrix. Comparison of the operation cost for n transformations:
Quaternion< Scalar > & operator*= ( const Quaternion< Scalar > &  other)
inline
See Also
operator*(Quaternion)
Quaternion< Scalar > & operator= ( const AngleAxisType aa)
inline

Set *this from an angle-axis aa and returns a reference to *this

Quaternion<Scalar>& operator= ( const MatrixBase< Derived > &  xpr)
inline

Set *this from the expression xpr:

  • if xpr is a 4x1 vector, then xpr is assumed to be a quaternion
  • if xpr is a 3x3 matrix, then xpr is assumed to be rotation matrix and xpr is converted to a quaternion
Quaternion<Scalar>& setFromTwoVectors ( const MatrixBase< Derived1 > &  a,
const MatrixBase< Derived2 > &  b 
)
inline

Sets *this to be a quaternion representing a rotation sending the vector a to the vector b.

Returns
a reference to *this.

Note that the two input vectors do not have to be normalized.

Quaternion& setIdentity ( )
inline
Quaternion< Scalar > slerp ( Scalar  t,
const Quaternion< Scalar > &  other 
) const
Returns
the spherical linear interpolation between the two quaternions *this and other at the parameter t
Scalar squaredNorm ( ) const
inline
Returns
the squared norm of the quaternion's coefficients
See Also
Quaternion::norm(), MatrixBase::squaredNorm()
Quaternion< Scalar >::Matrix3 toRotationMatrix ( void  ) const
inline

Convert the quaternion to a 3x3 rotation matrix

const Block<Coefficients,3,1> vec ( ) const
inline
Returns
a read-only vector expression of the imaginary part (x,y,z)
Block<Coefficients,3,1> vec ( )
inline
Returns
a vector expression of the imaginary part (x,y,z)
Scalar w ( ) const
inline
Returns
the w coefficient
Scalar& w ( )
inline
Returns
a reference to the w coefficient
Scalar x ( ) const
inline
Returns
the x coefficient
Scalar& x ( )
inline
Returns
a reference to the x coefficient
Scalar y ( ) const
inline
Returns
the y coefficient
Scalar& y ( )
inline
Returns
a reference to the y coefficient
Scalar z ( ) const
inline
Returns
the z coefficient
Scalar& z ( )
inline
Returns
a reference to the z coefficient

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