Public Types | Public Member Functions | Static Public Member Functions | Friends
Quaternion< _Scalar, _Options > Class Template Reference

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

#include <Quaternion.h>

+ Inheritance diagram for Quaternion< _Scalar, _Options >:

List of all members.

Public Types

typedef Base::AngleAxisType AngleAxisType
typedef Matrix< Scalar, 3, 3 > Matrix3
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
typedef _Scalar Scalar
typedef Matrix< Scalar, 3, 1 > Vector3

Public Member Functions

Vector3 _transformVector (Vector3 v) const
internal::cast_return_type
< Quaternion< _Scalar,
_Options >, Quaternion
< NewScalarType > >::type 
cast () const
Coefficients & coeffs ()
const Coefficients & coeffs () const
Quaternion< Scalarconjugate () const
Scalar dot (const QuaternionBase< OtherDerived > &other) const
Quaternion< Scalarinverse () const
bool isApprox (const QuaternionBase< OtherDerived > &other, RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
RotationMatrixType matrix () const
Scalar norm () const
void normalize ()
Quaternion< Scalarnormalized () const
Transform< Scalar, Dim, Isometryoperator* (const Translation< Scalar, Dim > &t) const
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
internal::rotation_base_generic_product_selector
< Quaternion< _Scalar,
_Options >, OtherDerived,
OtherDerived::IsVectorAtCompileTime >
::ReturnType 
operator* (const EigenBase< OtherDerived > &e) const
Transform< Scalar, Dim, Mode > operator* (const Transform< Scalar, Dim, Mode, Options > &t) const
 Quaternion ()
 Quaternion (Scalar w, Scalar x, Scalar y, Scalar z)
 Quaternion (const Scalar *data)
template<class Derived >
 Quaternion (const QuaternionBase< Derived > &other)
 Quaternion (const AngleAxisType &aa)
template<typename Derived >
 Quaternion (const MatrixBase< Derived > &other)
template<typename OtherScalar , int OtherOptions>
 Quaternion (const Quaternion< OtherScalar, OtherOptions > &other)
Quaternion< _Scalar, _Options > & setFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
QuaternionBasesetIdentity ()
Quaternion< Scalarslerp (Scalar t, const QuaternionBase< OtherDerived > &other) const
Scalar squaredNorm () const
Matrix3 toRotationMatrix () const
const VectorBlock< const
Coefficients, 3 > 
vec () const
VectorBlock< Coefficients, 3 > vec ()
Scalar w () const
Scalarw ()
Scalar x () const
Scalarx ()
Scalar y () const
Scalary ()
Scalar z () const
Scalarz ()

Static Public Member Functions

template<typename Derived1 , typename Derived2 >
static Quaternion FromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
static Quaternion< ScalarIdentity ()

Friends

RotationMatrixType operator* (const EigenBase< OtherDerived > &l, const Quaternion< _Scalar, _Options > &r)
Transform< Scalar, Dim, Affineoperator* (const DiagonalMatrix< Scalar, Dim > &l, const Quaternion< _Scalar, _Options > &r)

Detailed Description

template<typename _Scalar, int _Options>
class Eigen::Quaternion< _Scalar, _Options >

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

Reimplemented from QuaternionBase< Quaternion< _Scalar, _Options > >.

typedef Matrix<Scalar,3,3> Matrix3 [inherited]

the equivalent rotation matrix type

typedef Matrix<Scalar,Dim,Dim> RotationMatrixType [inherited]

corresponding linear transformation matrix type

typedef _Scalar Scalar

the scalar type of the coefficients

Reimplemented from QuaternionBase< Quaternion< _Scalar, _Options > >.

typedef Matrix<Scalar,3,1> Vector3 [inherited]

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 Scalar data) [inline]

Constructs and initialize a quaternion from the array data

Quaternion ( const QuaternionBase< Derived > &  other) [inline]

Copy constructor

Quaternion ( const AngleAxisType aa) [inline, explicit]

Constructs and initializes a quaternion from the angle-axis aa

Quaternion ( const MatrixBase< Derived > &  other) [inline, explicit]

Constructs and initializes a quaternion from either:

  • a rotation matrix expression,
  • a 4D vector expression representing quaternion coefficients.
Quaternion ( const Quaternion< OtherScalar, OtherOptions > &  other) [inline, explicit]

Explicit copy constructor with scalar conversion

References Quaternion< _Scalar, _Options >::coeffs().


Member Function Documentation

Vector3 _transformVector ( Vector3  v) const [inline, inherited]

return the result vector of v through the rotation

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:
  • Quaternion2: 30n
  • Via a Matrix3: 24 + 15n
internal::cast_return_type<Quaternion< _Scalar, _Options > ,Quaternion<NewScalarType> >::type cast ( ) const [inline, inherited]
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.

Coefficients& coeffs ( ) [inline]
Returns:
a vector expression of the coefficients (x,y,z,w)

Reimplemented from QuaternionBase< Quaternion< _Scalar, _Options > >.

Referenced by Quaternion< _Scalar, _Options >::Quaternion().

const Coefficients& coeffs ( ) const [inline]
Returns:
a read-only vector expression of the coefficients (x,y,z,w)

Reimplemented from QuaternionBase< Quaternion< _Scalar, _Options > >.

Quaternion<Scalar> conjugate ( ) const [inherited]
Returns:
the conjugated quaternion
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:
Quaternion2::inverse()
Scalar dot ( const QuaternionBase< OtherDerived > &  other) const [inline, inherited]
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()

References QuaternionBase< Derived >::coeffs().

Quaternion< Scalar, Options > FromTwoVectors ( const MatrixBase< Derived1 > &  a,
const MatrixBase< Derived2 > &  b 
) [static]

Returns a quaternion representing a rotation between the two arbitrary vectors a and b. In other words, the built rotation represent a rotation sending the line of direction a to the line of direction b, both lines passing through the origin.

Returns:
resulting quaternion

Note that the two input vectors do not have to be normalized, and do not need to have the same norm.

References QuaternionBase< Derived >::setFromTwoVectors().

static Quaternion<Scalar> Identity ( ) [inline, static, inherited]
Returns:
a quaternion representing an identity rotation
See also:
MatrixBase::Identity()
Quaternion<Scalar> inverse ( ) const [inherited]
Returns:
the quaternion describing the inverse rotation
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:
QuaternionBase::conjugate()

Reimplemented from RotationBase< Quaternion< _Scalar, _Options >, 3 >.

bool isApprox ( const QuaternionBase< OtherDerived > &  other,
RealScalar  prec = NumTraits<Scalar>::dummy_precision() 
) const [inline, inherited]
Returns:
true if *this is approximately equal to other, within the precision determined by prec.
See also:
MatrixBase::isApprox()

References QuaternionBase< Derived >::coeffs().

RotationMatrixType matrix ( ) const [inline, inherited]
Returns:
an equivalent rotation matrix This function is added to be conform with the Transform class' naming scheme.
Scalar norm ( ) const [inline, inherited]
Returns:
the norm of the quaternion's coefficients
See also:
QuaternionBase::squaredNorm(), MatrixBase::norm()

References QuaternionBase< Derived >::coeffs().

void normalize ( void  ) [inline, inherited]

Normalizes the quaternion *this

See also:
normalized(), MatrixBase::normalize()

References QuaternionBase< Derived >::coeffs().

Quaternion<Scalar> normalized ( ) const [inline, inherited]
Returns:
a normalized copy of *this
See also:
normalize(), MatrixBase::normalized()

References QuaternionBase< Derived >::coeffs().

Transform<Scalar,Dim,Isometry> operator* ( const Translation< Scalar, Dim > &  t) const [inline, inherited]
Returns:
the concatenation of the rotation *this with a translation t
RotationMatrixType operator* ( const UniformScaling< Scalar > &  s) const [inline, inherited]
Returns:
the concatenation of the rotation *this with a uniform scaling s
internal::rotation_base_generic_product_selector<Quaternion< _Scalar, _Options > ,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType operator* ( const EigenBase< OtherDerived > &  e) const [inline, inherited]
Returns:
the concatenation of the rotation *this with a generic expression e e can be:
  • a DimxDim linear transformation matrix
  • a DimxDim diagonal matrix (axis aligned scaling)
  • a vector of size Dim
Transform<Scalar,Dim,Mode> operator* ( const Transform< Scalar, Dim, Mode, Options > &  t) const [inline, inherited]
Returns:
the concatenation of the rotation *this with a transformation t
Quaternion< _Scalar, _Options > & setFromTwoVectors ( const MatrixBase< Derived1 > &  a,
const MatrixBase< Derived2 > &  b 
) [inherited]
Returns:
the quaternion which transform a into b through a rotation

Sets *this to be a quaternion representing a rotation between the two arbitrary vectors a and b. In other words, the built rotation represent a rotation sending the line of direction a to the line of direction b, both lines passing through the origin.

Returns:
a reference to *this.

Note that the two input vectors do not have to be normalized, and do not need to have the same norm.

QuaternionBase& setIdentity ( ) [inline, inherited]
See also:
QuaternionBase::Identity(), MatrixBase::setIdentity()

References QuaternionBase< Derived >::coeffs().

Quaternion<Scalar> slerp ( Scalar  t,
const QuaternionBase< OtherDerived > &  other 
) const [inherited]
Returns:
an interpolation for a constant motion between other and *this t in [0;1] see http://en.wikipedia.org/wiki/Slerp
the spherical linear interpolation between the two quaternions *this and other at the parameter t
Scalar squaredNorm ( ) const [inline, inherited]
Returns:
the squared norm of the quaternion's coefficients
See also:
QuaternionBase::norm(), MatrixBase::squaredNorm()

References QuaternionBase< Derived >::coeffs().

Matrix3 toRotationMatrix ( void  ) const [inherited]
Returns:
an equivalent 3x3 rotation matrix

Convert the quaternion to a 3x3 rotation matrix. The quaternion is required to be normalized, otherwise the result is undefined.

Reimplemented from RotationBase< Quaternion< _Scalar, _Options >, 3 >.

const VectorBlock<const Coefficients,3> vec ( ) const [inline, inherited]
Returns:
a read-only vector expression of the imaginary part (x,y,z)

References QuaternionBase< Derived >::coeffs().

VectorBlock<Coefficients,3> vec ( ) [inline, inherited]
Returns:
a vector expression of the imaginary part (x,y,z)

References QuaternionBase< Derived >::coeffs().

Scalar w ( ) const [inline, inherited]
Returns:
the w coefficient
Scalar& w ( ) [inline, inherited]
Returns:
a reference to the w coefficient
Scalar x ( ) const [inline, inherited]
Returns:
the x coefficient
Scalar& x ( ) [inline, inherited]
Returns:
a reference to the x coefficient
Scalar y ( ) const [inline, inherited]
Returns:
the y coefficient
Scalar& y ( ) [inline, inherited]
Returns:
a reference to the y coefficient
Scalar z ( ) const [inline, inherited]
Returns:
the z coefficient
Scalar& z ( ) [inline, inherited]
Returns:
a reference to the z coefficient

Friends And Related Function Documentation

RotationMatrixType operator* ( const EigenBase< OtherDerived > &  l,
const Quaternion< _Scalar, _Options > &  r 
) [friend, inherited]
Returns:
the concatenation of a linear transformation l with the rotation r
Transform<Scalar,Dim,Affine> operator* ( const DiagonalMatrix< Scalar, Dim > &  l,
const Quaternion< _Scalar, _Options > &  r 
) [friend, inherited]
Returns:
the concatenation of a scaling l with the rotation r

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