Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes
Eigen::Quaternion< _Scalar > Class Template Reference

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

#include <Quaternion.h>

+ Inheritance diagram for Eigen::Quaternion< _Scalar >:
+ Collaboration diagram for Eigen::Quaternion< _Scalar >:

Public Types

typedef _Scalar Scalar
 
typedef Matrix< Scalar, 4, 1 > Coefficients
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef AngleAxis< ScalarAngleAxisType
 
typedef _Scalar Scalar
 
typedef internal::traits< Quaternion >::Coefficients Coefficients
 
typedef Base::AngleAxisType AngleAxisType
 
- Public Types inherited from Eigen::QuaternionBase< Quaternion< _Scalar, _Options > >
enum  
 
typedef internal::traits< Quaternion< _Scalar, _Options > >::Scalar Scalar
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef internal::traits< Quaternion< _Scalar, _Options > >::Coefficients Coefficients
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef AngleAxis< ScalarAngleAxisType
 
- Public Types inherited from Eigen::RotationBase< Quaternion< _Scalar, _Options >, 3 >
enum  
 
enum  
 
typedef ei_traits< Quaternion< _Scalar, _Options > >::Scalar Scalar
 
typedef internal::traits< Quaternion< _Scalar, _Options > >::Scalar Scalar
 
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
 
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
 
typedef Matrix< Scalar, Dim, 1 > VectorType
 
- Public Types inherited from Eigen::RotationBase< Quaternion< _Scalar >, 3 >
enum  
 
enum  
 
typedef ei_traits< Quaternion< _Scalar > >::Scalar Scalar
 
typedef internal::traits< Quaternion< _Scalar > >::Scalar Scalar
 
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
 
typedef Matrix< Scalar, Dim, Dim > RotationMatrixType
 
typedef Matrix< Scalar, Dim, 1 > VectorType
 

Public Member Functions

Scalar x () const
 
Scalar y () const
 
Scalar z () const
 
Scalar w () const
 
Scalarx ()
 
Scalary ()
 
Scalarz ()
 
Scalarw ()
 
const Block< const Coefficients, 3, 1 > vec () const
 
Block< Coefficients, 3, 1 > vec ()
 
const Coefficientscoeffs () const
 
Coefficientscoeffs ()
 
 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)
 
Quaternionoperator= (const Quaternion &other)
 
Quaternionoperator= (const AngleAxisType &aa)
 
template<typename Derived >
Quaternionoperator= (const MatrixBase< Derived > &m)
 
QuaternionsetIdentity ()
 
Scalar squaredNorm () const
 
Scalar norm () const
 
void normalize ()
 
Quaternion normalized () const
 
Scalar eigen2_dot (const Quaternion &other) const
 
Scalar angularDistance (const Quaternion &other) const
 
Matrix3 toRotationMatrix (void) const
 
template<typename Derived1 , typename Derived2 >
QuaternionsetFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
Quaternion operator* (const Quaternion &q) const
 
Quaternionoperator*= (const Quaternion &q)
 
Quaternion inverse (void) const
 
Quaternion conjugate (void) const
 
Quaternion slerp (Scalar t, const Quaternion &other) const
 
template<typename Derived >
Vector3 operator* (const MatrixBase< Derived > &vec) const
 
template<typename NewScalarType >
internal::cast_return_type< Quaternion, Quaternion< NewScalarType > >::type cast () const
 
template<typename OtherScalarType >
 Quaternion (const Quaternion< OtherScalarType > &other)
 
bool isApprox (const Quaternion &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
 
 Quaternion ()
 
 Quaternion (const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
 
 Quaternion (const Scalar *data)
 
template<class Derived >
EIGEN_STRONG_INLINE 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)
 
Coefficientscoeffs ()
 
const Coefficientscoeffs () const
 
template<typename Derived >
Quaternion< Scalar > & operator= (const MatrixBase< Derived > &xpr)
 
template<typename Derived1 , typename Derived2 >
Quaternion< Scalar > & setFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
template<typename Derived1 , typename Derived2 >
Quaternion< Scalar, Options > FromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
- Public Member Functions inherited from Eigen::QuaternionBase< Quaternion< _Scalar, _Options > >
Scalar x () const
 
Scalarx ()
 
Scalar y () const
 
Scalary ()
 
Scalar z () const
 
Scalarz ()
 
Scalar w () const
 
Scalarw ()
 
const VectorBlock< const Coefficients, 3 > vec () const
 
VectorBlock< Coefficients, 3 > vec ()
 
const internal::traits< Quaternion< _Scalar, _Options > >::Coefficients & coeffs () const
 
internal::traits< Quaternion< _Scalar, _Options > >::Coefficients & coeffs ()
 
EIGEN_STRONG_INLINE QuaternionBase< Quaternion< _Scalar, _Options > > & operator= (const QuaternionBase< Quaternion< _Scalar, _Options > > &other)
 
EIGEN_STRONG_INLINE Quaternion< _Scalar, _Options > & operator= (const QuaternionBase< OtherDerived > &other)
 
Quaternion< _Scalar, _Options > & operator= (const AngleAxisType &aa)
 
Quaternion< _Scalar, _Options > & operator= (const MatrixBase< OtherDerived > &m)
 
QuaternionBasesetIdentity ()
 
Scalar squaredNorm () const
 
Scalar norm () const
 
void normalize ()
 
Quaternion< Scalarnormalized () const
 
Scalar dot (const QuaternionBase< OtherDerived > &other) const
 
Scalar angularDistance (const QuaternionBase< OtherDerived > &other) const
 
Matrix3 toRotationMatrix () const
 
Quaternion< _Scalar, _Options > & setFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
EIGEN_STRONG_INLINE Quaternion< Scalaroperator* (const QuaternionBase< OtherDerived > &q) const
 
EIGEN_STRONG_INLINE Quaternion< _Scalar, _Options > & operator*= (const QuaternionBase< OtherDerived > &q)
 
Quaternion< Scalarinverse () const
 
Quaternion< Scalarconjugate () const
 
Quaternion< Scalarslerp (const Scalar &t, const QuaternionBase< OtherDerived > &other) const
 
bool isApprox (const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
EIGEN_STRONG_INLINE Vector3 _transformVector (Vector3 v) const
 
internal::cast_return_type< Quaternion< _Scalar, _Options >, Quaternion< NewScalarType > >::type cast () const
 
- Public Member Functions inherited from Eigen::RotationBase< Quaternion< _Scalar, _Options >, 3 >
const Quaternion< _Scalar, _Options > & derived () const
 
Quaternion< _Scalar, _Options > & derived ()
 
const Quaternion< _Scalar, _Options > & derived () const
 
Quaternion< _Scalar, _Options > & derived ()
 
RotationMatrixType toRotationMatrix () const
 
RotationMatrixType toRotationMatrix () const
 
Quaternion< _Scalar, _Options > inverse () const
 
Quaternion< _Scalar, _Options > 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
 
Transform< Scalar, Dim, Isometry > operator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
 
EIGEN_STRONG_INLINE 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
 
RotationMatrixType matrix () const
 
VectorType _transformVector (const OtherVectorType &v) const
 
- Public Member Functions inherited from Eigen::RotationBase< Quaternion< _Scalar >, 3 >
const Quaternion< _Scalar > & derived () const
 
Quaternion< _Scalar > & derived ()
 
const Quaternion< _Scalar > & derived () const
 
Quaternion< _Scalar > & derived ()
 
RotationMatrixType toRotationMatrix () const
 
RotationMatrixType toRotationMatrix () const
 
Quaternion< _Scalar > inverse () const
 
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
 
Transform< Scalar, Dim, Isometry > operator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
 
EIGEN_STRONG_INLINE internal::rotation_base_generic_product_selector< Quaternion< _Scalar >, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator* (const EigenBase< OtherDerived > &e) const
 
Transform< Scalar, Dim, Mode > operator* (const Transform< Scalar, Dim, Mode, Options > &t) const
 
RotationMatrixType matrix () const
 
VectorType _transformVector (const OtherVectorType &v) const
 

Static Public Member Functions

static Quaternion Identity ()
 
template<typename Derived1 , typename Derived2 >
static Quaternion FromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
- Static Public Member Functions inherited from Eigen::QuaternionBase< Quaternion< _Scalar, _Options > >
static Quaternion< ScalarIdentity ()
 

Static Protected Member Functions

static EIGEN_STRONG_INLINE void _check_template_params ()
 

Protected Attributes

Coefficients m_coeffs
 

Detailed Description

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

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

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
Template Parameters
_Scalarthe scalar type, i.e., the type of the coefficients
_Optionscontrols the memory alignement of the coeffecients. Can be # AutoAlign or # DontAlign. Default is AutoAlign.

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

Definition at line 47 of file Quaternion.h.

Member Typedef Documentation

template<typename _Scalar>
typedef AngleAxis<Scalar> Eigen::Quaternion< _Scalar >::AngleAxisType

the equivalent angle-axis type

Definition at line 66 of file Quaternion.h.

template<typename _Scalar>
typedef Matrix<Scalar, 4, 1> Eigen::Quaternion< _Scalar >::Coefficients

the type of the Coefficients 4-vector

Definition at line 60 of file Quaternion.h.

template<typename _Scalar>
typedef Matrix<Scalar,3,3> Eigen::Quaternion< _Scalar >::Matrix3

the equivalent rotation matrix type

Definition at line 64 of file Quaternion.h.

template<typename _Scalar>
typedef _Scalar Eigen::Quaternion< _Scalar >::Scalar

the scalar type of the coefficients

Definition at line 57 of file Quaternion.h.

template<typename _Scalar>
typedef Matrix<Scalar,3,1> Eigen::Quaternion< _Scalar >::Vector3

the type of a 3D vector

Definition at line 62 of file Quaternion.h.

Constructor & Destructor Documentation

template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( )
inline

Default constructor leaving the quaternion uninitialized.

Definition at line 99 of file Quaternion.h.

99 {}
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::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]

Definition at line 108 of file Quaternion.h.

109  { m_coeffs << x, y, z, w; }
Scalar y() const
Definition: Quaternion.h:71
Scalar z() const
Definition: Quaternion.h:73
Scalar x() const
Definition: Quaternion.h:69
Scalar w() const
Definition: Quaternion.h:75
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( const Quaternion< _Scalar > &  other)
inline

Copy constructor

Definition at line 112 of file Quaternion.h.

112 { m_coeffs = other.m_coeffs; }
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( const AngleAxisType aa)
inlineexplicit

Constructs and initializes a quaternion from the angle-axis aa

Definition at line 115 of file Quaternion.h.

115 { *this = aa; }
template<typename _Scalar>
template<typename Derived >
Eigen::Quaternion< _Scalar >::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>)

Definition at line 123 of file Quaternion.h.

123 { *this = other; }
template<typename _Scalar>
template<typename OtherScalarType >
Eigen::Quaternion< _Scalar >::Quaternion ( const Quaternion< OtherScalarType > &  other)
inlineexplicit

Copy constructor with scalar type conversion

Definition at line 192 of file Quaternion.h.

193  { m_coeffs = other.coeffs().template cast<Scalar>(); }
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( )
inline

Default constructor leaving the quaternion uninitialized.

Definition at line 243 of file Quaternion.h.

243 {}
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( const Scalar w,
const Scalar x,
const Scalar y,
const 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]

Definition at line 252 of file Quaternion.h.

252 : m_coeffs(x, y, z, w){}
Scalar y() const
Definition: Quaternion.h:71
Scalar z() const
Definition: Quaternion.h:73
Scalar x() const
Definition: Quaternion.h:69
Scalar w() const
Definition: Quaternion.h:75
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( const Scalar data)
inline

Constructs and initialize a quaternion from the array data

Definition at line 255 of file Quaternion.h.

255 : m_coeffs(data) {}
template<typename _Scalar>
template<class Derived >
EIGEN_STRONG_INLINE Eigen::Quaternion< _Scalar >::Quaternion ( const QuaternionBase< Derived > &  other)
inline

Copy constructor

Definition at line 258 of file Quaternion.h.

258 { this->Base::operator=(other); }
template<typename _Scalar>
Eigen::Quaternion< _Scalar >::Quaternion ( const AngleAxisType aa)
inlineexplicit

Constructs and initializes a quaternion from the angle-axis aa

Definition at line 261 of file Quaternion.h.

261 { *this = aa; }
template<typename _Scalar>
template<typename Derived >
Eigen::Quaternion< _Scalar >::Quaternion ( const MatrixBase< Derived > &  other)
inlineexplicit

Constructs and initializes a quaternion from either:

  • a rotation matrix expression,
  • a 4D vector expression representing quaternion coefficients.

Definition at line 268 of file Quaternion.h.

268 { *this = other; }
template<typename _Scalar>
template<typename OtherScalar , int OtherOptions>
Eigen::Quaternion< _Scalar >::Quaternion ( const Quaternion< OtherScalar, OtherOptions > &  other)
inlineexplicit

Explicit copy constructor with scalar conversion

Definition at line 272 of file Quaternion.h.

273  { m_coeffs = other.coeffs().template cast<Scalar>(); }

Member Function Documentation

template<typename Scalar >
Scalar Eigen::Quaternion< Scalar >::angularDistance ( const Quaternion< _Scalar > &  other) const
inline
Returns
the angle (in radian) between two rotations
See also
eigen2_dot()

Definition at line 404 of file Quaternion.h.

405 {
406  double d = ei_abs(this->eigen2_dot(other));
407  if (d>=1.0)
408  return 0;
409  return Scalar(2) * std::acos(d);
410 }
Scalar eigen2_dot(const Quaternion &other) const
Definition: Quaternion.h:161
template<typename _Scalar>
template<typename NewScalarType >
internal::cast_return_type<Quaternion,Quaternion<NewScalarType> >::type Eigen::Quaternion< _Scalar >::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.

Definition at line 187 of file Quaternion.h.

188  { return typename internal::cast_return_type<Quaternion,Quaternion<NewScalarType> >::type(*this); }
template<typename _Scalar>
const Coefficients& Eigen::Quaternion< _Scalar >::coeffs ( ) const
inline
Returns
a read-only vector expression of the coefficients (x,y,z,w)

Definition at line 93 of file Quaternion.h.

93 { return m_coeffs; }
template<typename _Scalar>
Coefficients& Eigen::Quaternion< _Scalar >::coeffs ( )
inline
Returns
a vector expression of the coefficients (x,y,z,w)

Definition at line 96 of file Quaternion.h.

96 { return m_coeffs; }
template<typename Scalar >
Quaternion< Scalar > Eigen::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()

Definition at line 395 of file Quaternion.h.

396 {
397  return Quaternion(this->w(),-this->x(),-this->y(),-this->z());
398 }
Scalar y() const
Definition: Quaternion.h:71
Scalar z() const
Definition: Quaternion.h:73
Scalar x() const
Definition: Quaternion.h:69
Scalar w() const
Definition: Quaternion.h:75
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::eigen2_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()

Definition at line 161 of file Quaternion.h.

161 { return m_coeffs.eigen2_dot(other.m_coeffs); }
template<typename _Scalar>
template<typename Derived1 , typename Derived2 >
Quaternion<Scalar,Options> Eigen::Quaternion< _Scalar >::FromTwoVectors ( const MatrixBase< Derived1 > &  a,
const MatrixBase< Derived2 > &  b 
)

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.

Definition at line 623 of file Quaternion.h.

624 {
625  Quaternion quat;
626  quat.setFromTwoVectors(a, b);
627  return quat;
628 }
template<typename _Scalar>
static Quaternion Eigen::Quaternion< _Scalar >::Identity ( )
inlinestatic
Returns
a quaternion representing an identity rotation
See also
MatrixBase::Identity()

Definition at line 133 of file Quaternion.h.

133 { return Quaternion(1, 0, 0, 0); }
template<typename Scalar >
Quaternion< Scalar > Eigen::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()

Definition at line 375 of file Quaternion.h.

376 {
377  // FIXME should this function be called multiplicativeInverse and conjugate() be called inverse() or opposite() ??
378  Scalar n2 = this->squaredNorm();
379  if (n2 > 0)
380  return Quaternion(conjugate().coeffs() / n2);
381  else
382  {
383  // return an invalid result to flag the error
384  return Quaternion(Coefficients::Zero());
385  }
386 }
Quaternion conjugate(void) const
Definition: Quaternion.h:395
const Coefficients & coeffs() const
Definition: Quaternion.h:93
Scalar squaredNorm() const
Definition: Quaternion.h:142
template<typename _Scalar>
bool Eigen::Quaternion< _Scalar >::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()

Definition at line 199 of file Quaternion.h.

200  { return m_coeffs.isApprox(other.m_coeffs, prec); }
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::norm ( ) const
inline
Returns
the norm of the quaternion's coefficients
See also
Quaternion::squaredNorm(), MatrixBase::norm()

Definition at line 147 of file Quaternion.h.

147 { return m_coeffs.norm(); }
template<typename _Scalar>
void Eigen::Quaternion< _Scalar >::normalize ( void  )
inline

Normalizes the quaternion *this

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

Definition at line 151 of file Quaternion.h.

151 { m_coeffs.normalize(); }
template<typename _Scalar>
Quaternion Eigen::Quaternion< _Scalar >::normalized ( ) const
inline
Returns
a normalized version of *this
See also
normalize(), MatrixBase::normalized()

Definition at line 154 of file Quaternion.h.

154 { return Quaternion(m_coeffs.normalized()); }
template<typename Scalar >
Quaternion< Scalar > Eigen::Quaternion< Scalar >::operator* ( const Quaternion< _Scalar > &  other) const
inline
Returns
the concatenation of two rotations as a quaternion-quaternion product

Definition at line 228 of file Quaternion.h.

229 {
230  return ei_quaternion_product(*this,other);
231 }
template<typename Scalar >
template<typename Derived >
Quaternion< Scalar >::Vector3 Eigen::Quaternion< Scalar >::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:

Definition at line 250 of file Quaternion.h.

251 {
252  // Note that this algorithm comes from the optimization by hand
253  // of the conversion to a Matrix followed by a Matrix/Vector product.
254  // It appears to be much faster than the common algorithm found
255  // in the litterature (30 versus 39 flops). It also requires two
256  // Vector3 as temporaries.
257  Vector3 uv;
258  uv = 2 * this->vec().cross(v);
259  return v + this->w() * uv + this->vec().cross(uv);
260 }
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Scalar w() const
Definition: Quaternion.h:75
Matrix< Scalar, 3, 1 > Vector3
Definition: Quaternion.h:62
template<typename Scalar >
Quaternion< Scalar > & Eigen::Quaternion< Scalar >::operator*= ( const Quaternion< _Scalar > &  other)
inline
See also
operator*(Quaternion)

Definition at line 235 of file Quaternion.h.

236 {
237  return (*this = *this * other);
238 }
template<typename Scalar >
Quaternion< Scalar > & Eigen::Quaternion< Scalar >::operator= ( const AngleAxisType aa)
inline

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

Definition at line 272 of file Quaternion.h.

273 {
274  Scalar ha = Scalar(0.5)*aa.angle(); // Scalar(0.5) to suppress precision loss warnings
275  this->w() = ei_cos(ha);
276  this->vec() = ei_sin(ha) * aa.axis();
277  return *this;
278 }
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Scalar w() const
Definition: Quaternion.h:75
template<typename _Scalar>
template<typename Derived >
Quaternion<Scalar>& Eigen::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

Definition at line 287 of file Quaternion.h.

288 {
289  ei_quaternion_assign_impl<Derived>::run(*this, xpr.derived());
290  return *this;
291 }
template<typename _Scalar>
template<typename Derived1 , typename Derived2 >
Quaternion<Scalar>& Eigen::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.

Definition at line 338 of file Quaternion.h.

339 {
340  Vector3 v0 = a.normalized();
341  Vector3 v1 = b.normalized();
342  Scalar c = v0.eigen2_dot(v1);
343 
344  // if dot == 1, vectors are the same
345  if (ei_isApprox(c,Scalar(1)))
346  {
347  // set to identity
348  this->w() = 1; this->vec().setZero();
349  return *this;
350  }
351  // if dot == -1, vectors are opposites
352  if (ei_isApprox(c,Scalar(-1)))
353  {
354  this->vec() = v0.unitOrthogonal();
355  this->w() = 0;
356  return *this;
357  }
358 
359  Vector3 axis = v0.cross(v1);
360  Scalar s = ei_sqrt((Scalar(1)+c)*Scalar(2));
361  Scalar invs = Scalar(1)/s;
362  this->vec() = axis * invs;
363  this->w() = s * Scalar(0.5);
364 
365  return *this;
366 }
const Block< const Coefficients, 3, 1 > vec() const
Definition: Quaternion.h:87
Scalar w() const
Definition: Quaternion.h:75
Matrix< Scalar, 3, 1 > Vector3
Definition: Quaternion.h:62
template<typename _Scalar>
Quaternion& Eigen::Quaternion< _Scalar >::setIdentity ( )
inline
See also
Quaternion::Identity(), MatrixBase::setIdentity()

Definition at line 137 of file Quaternion.h.

137 { m_coeffs << 0, 0, 0, 1; return *this; }
template<typename Scalar >
Quaternion< Scalar > Eigen::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

Definition at line 416 of file Quaternion.h.

417 {
418  static const Scalar one = Scalar(1) - machine_epsilon<Scalar>();
419  Scalar d = this->eigen2_dot(other);
420  Scalar absD = ei_abs(d);
421 
422  Scalar scale0;
423  Scalar scale1;
424 
425  if (absD>=one)
426  {
427  scale0 = Scalar(1) - t;
428  scale1 = t;
429  }
430  else
431  {
432  // theta is the angle between the 2 quaternions
433  Scalar theta = std::acos(absD);
434  Scalar sinTheta = ei_sin(theta);
435 
436  scale0 = ei_sin( ( Scalar(1) - t ) * theta) / sinTheta;
437  scale1 = ei_sin( ( t * theta) ) / sinTheta;
438  if (d<0)
439  scale1 = -scale1;
440  }
441 
442  return Quaternion<Scalar>(scale0 * coeffs() + scale1 * other.coeffs());
443 }
Scalar eigen2_dot(const Quaternion &other) const
Definition: Quaternion.h:161
const Coefficients & coeffs() const
Definition: Quaternion.h:93
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::squaredNorm ( ) const
inline
Returns
the squared norm of the quaternion's coefficients
See also
Quaternion::norm(), MatrixBase::squaredNorm()

Definition at line 142 of file Quaternion.h.

142 { return m_coeffs.squaredNorm(); }
template<typename Scalar >
Quaternion< Scalar >::Matrix3 Eigen::Quaternion< Scalar >::toRotationMatrix ( void  ) const
inline

Convert the quaternion to a 3x3 rotation matrix

Definition at line 296 of file Quaternion.h.

297 {
298  // NOTE if inlined, then gcc 4.2 and 4.4 get rid of the temporary (not gcc 4.3 !!)
299  // if not inlined then the cost of the return by value is huge ~ +35%,
300  // however, not inlining this function is an order of magnitude slower, so
301  // it has to be inlined, and so the return by value is not an issue
302  Matrix3 res;
303 
304  const Scalar tx = Scalar(2)*this->x();
305  const Scalar ty = Scalar(2)*this->y();
306  const Scalar tz = Scalar(2)*this->z();
307  const Scalar twx = tx*this->w();
308  const Scalar twy = ty*this->w();
309  const Scalar twz = tz*this->w();
310  const Scalar txx = tx*this->x();
311  const Scalar txy = ty*this->x();
312  const Scalar txz = tz*this->x();
313  const Scalar tyy = ty*this->y();
314  const Scalar tyz = tz*this->y();
315  const Scalar tzz = tz*this->z();
316 
317  res.coeffRef(0,0) = Scalar(1)-(tyy+tzz);
318  res.coeffRef(0,1) = txy-twz;
319  res.coeffRef(0,2) = txz+twy;
320  res.coeffRef(1,0) = txy+twz;
321  res.coeffRef(1,1) = Scalar(1)-(txx+tzz);
322  res.coeffRef(1,2) = tyz-twx;
323  res.coeffRef(2,0) = txz-twy;
324  res.coeffRef(2,1) = tyz+twx;
325  res.coeffRef(2,2) = Scalar(1)-(txx+tyy);
326 
327  return res;
328 }
Scalar y() const
Definition: Quaternion.h:71
Scalar z() const
Definition: Quaternion.h:73
Scalar x() const
Definition: Quaternion.h:69
Scalar w() const
Definition: Quaternion.h:75
Matrix< Scalar, 3, 3 > Matrix3
Definition: Quaternion.h:64
template<typename _Scalar>
const Block<const Coefficients,3,1> Eigen::Quaternion< _Scalar >::vec ( ) const
inline
Returns
a read-only vector expression of the imaginary part (x,y,z)

Definition at line 87 of file Quaternion.h.

87 { return m_coeffs.template start<3>(); }
template<typename _Scalar>
Block<Coefficients,3,1> Eigen::Quaternion< _Scalar >::vec ( )
inline
Returns
a vector expression of the imaginary part (x,y,z)

Definition at line 90 of file Quaternion.h.

90 { return m_coeffs.template start<3>(); }
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::w ( ) const
inline
Returns
the w coefficient

Definition at line 75 of file Quaternion.h.

75 { return m_coeffs.coeff(3); }
template<typename _Scalar>
Scalar& Eigen::Quaternion< _Scalar >::w ( )
inline
Returns
a reference to the w coefficient

Definition at line 84 of file Quaternion.h.

84 { return m_coeffs.coeffRef(3); }
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::x ( ) const
inline
Returns
the x coefficient

Definition at line 69 of file Quaternion.h.

69 { return m_coeffs.coeff(0); }
template<typename _Scalar>
Scalar& Eigen::Quaternion< _Scalar >::x ( )
inline
Returns
a reference to the x coefficient

Definition at line 78 of file Quaternion.h.

78 { return m_coeffs.coeffRef(0); }
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::y ( ) const
inline
Returns
the y coefficient

Definition at line 71 of file Quaternion.h.

71 { return m_coeffs.coeff(1); }
template<typename _Scalar>
Scalar& Eigen::Quaternion< _Scalar >::y ( )
inline
Returns
a reference to the y coefficient

Definition at line 80 of file Quaternion.h.

80 { return m_coeffs.coeffRef(1); }
template<typename _Scalar>
Scalar Eigen::Quaternion< _Scalar >::z ( ) const
inline
Returns
the z coefficient

Definition at line 73 of file Quaternion.h.

73 { return m_coeffs.coeff(2); }
template<typename _Scalar>
Scalar& Eigen::Quaternion< _Scalar >::z ( )
inline
Returns
a reference to the z coefficient

Definition at line 82 of file Quaternion.h.

82 { return m_coeffs.coeffRef(2); }

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