Eigen::Quaternion< Scalar_, Options_ > Class Template Reference

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

+ Inheritance diagram for Eigen::Quaternion< Scalar_, Options_ >:

Public Types

enum  
 
typedef Base::AngleAxisType AngleAxisType
 
typedef QuaternionBase< Quaternion< Scalar_, Options_ > > Base
 
typedef internal::traits< Quaternion >::Coefficients Coefficients
 
typedef Scalar_ Scalar
 
- Public Types inherited from Eigen::QuaternionBase< Quaternion< Scalar_, Options_ > >
enum  
 
typedef AngleAxis< ScalarAngleAxisType
 
typedef RotationBase< Quaternion< Scalar_, Options_ >, 3 > Base
 
typedef internal::traits< Quaternion< Scalar_, Options_ > >::Coefficients Coefficients
 
typedef Coefficients::CoeffReturnType CoeffReturnType
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef std::conditional_t< bool(internal::traits< Quaternion< Scalar_, Options_ > >::Flags &LvalueBit), Scalar &, CoeffReturnTypeNonConstCoeffReturnType
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef internal::traits< Quaternion< Scalar_, Options_ > >::Scalar Scalar
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
- Public Types inherited from Eigen::RotationBase< Derived, Dim_ >
enum  { Dim }
 
typedef Matrix< Scalar, Dim, DimRotationMatrixType
 
typedef internal::traits< Derived >::Scalar Scalar
 
typedef Matrix< Scalar, Dim, 1 > VectorType
 

Public Member Functions

Coefficientscoeffs ()
 
const Coefficientscoeffs () const
 
template<typename Derived1 , typename Derived2 >
Quaternion< Scalar, Options > FromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
Quaternionoperator= (Quaternion &&other) EIGEN_NOEXCEPT_IF(std
 
 Quaternion ()
 
 Quaternion (const AngleAxisType &aa)
 
template<typename Derived >
 Quaternion (const MatrixBase< Derived > &other)
 
template<typename OtherScalar , int OtherOptions>
 Quaternion (const Quaternion< OtherScalar, OtherOptions > &other)
 
template<class Derived >
 Quaternion (const QuaternionBase< Derived > &other)
 
template<typename Derived >
 Quaternion (const Scalar &w, const Eigen::MatrixBase< Derived > &vec)
 
 Quaternion (const Scalar &w, const Scalar &x, const Scalar &y, const Scalar &z)
 
 Quaternion (const Scalar *data)
 
 Quaternion (Quaternion &&other) EIGEN_NOEXCEPT_IF(std
 
- Public Member Functions inherited from Eigen::QuaternionBase< Quaternion< Scalar_, Options_ > >
Vector3 _transformVector (const Vector3 &v) const
 
Scalar angularDistance (const QuaternionBase< OtherDerived > &other) const
 
internal::traits< Quaternion< Scalar_, Options_ > >::Scalar angularDistance (const QuaternionBase< OtherDerived > &other) const
 
internal::cast_return_type< Quaternion< Scalar_, Options_ >, Quaternion< NewScalarType > >::type cast () const
 
internal::traits< Quaternion< Scalar_, Options_ > >::Coefficientscoeffs ()
 
const internal::traits< Quaternion< Scalar_, Options_ > >::Coefficientscoeffs () const
 
Quaternion< Scalarconjugate () const
 
Scalar dot (const QuaternionBase< OtherDerived > &other) const
 
Quaternion< Scalarinverse () const
 
bool isApprox (const QuaternionBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
Scalar norm () const
 
void normalize ()
 
Quaternion< Scalarnormalized () const
 
bool operator!= (const QuaternionBase< OtherDerived > &other) const
 
Quaternion< typename internal::traits< Quaternion< Scalar_, Options_ > >::Scalaroperator* (const QuaternionBase< OtherDerived > &other) const
 
Quaternion< Scalaroperator* (const QuaternionBase< OtherDerived > &q) const
 
Quaternion< Scalar_, Options_ > & operator*= (const QuaternionBase< OtherDerived > &q)
 
Quaternion< Scalar_, Options_ > & operator= (const AngleAxisType &aa)
 
Quaternion< Scalar_, Options_ > & operator= (const MatrixBase< MatrixDerived > &xpr)
 
Quaternion< Scalar_, Options_ > & operator= (const MatrixBase< OtherDerived > &m)
 
Quaternion< Scalar_, Options_ > & operator= (const QuaternionBase< OtherDerived > &other)
 
QuaternionBase< Quaternion< Scalar_, Options_ > > & operator= (const QuaternionBase< Quaternion< Scalar_, Options_ > > &other)
 
bool operator== (const QuaternionBase< OtherDerived > &other) const
 
Quaternion< Scalar_, Options_ > & setFromTwoVectors (const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
 
QuaternionBasesetIdentity ()
 
Quaternion< Scalarslerp (const Scalar &t, const QuaternionBase< OtherDerived > &other) const
 
Quaternion< typename internal::traits< Quaternion< Scalar_, Options_ > >::Scalarslerp (const Scalar &t, const QuaternionBase< OtherDerived > &other) const
 
Scalar squaredNorm () const
 
Matrix3 toRotationMatrix () const
 
VectorBlock< Coefficients, 3 > vec ()
 
const VectorBlock< const Coefficients, 3 > vec () const
 
NonConstCoeffReturnType w ()
 
CoeffReturnType w () const
 
NonConstCoeffReturnType x ()
 
CoeffReturnType x () const
 
NonConstCoeffReturnType y ()
 
CoeffReturnType y () const
 
NonConstCoeffReturnType z ()
 
CoeffReturnType z () const
 
- Public Member Functions inherited from Eigen::RotationBase< Derived, Dim_ >
template<typename OtherVectorType >
VectorType _transformVector (const OtherVectorType &v) const
 
Derived & derived ()
 
const Derived & derived () const
 
Derived inverse () const
 
RotationMatrixType matrix () const
 
template<typename OtherDerived >
internal::rotation_base_generic_product_selector< Derived, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator* (const EigenBase< OtherDerived > &e) const
 
template<int Mode, int Options>
Transform< Scalar, Dim, Mode > operator* (const Transform< Scalar, Dim, Mode, Options > &t) const
 
Transform< Scalar, Dim, Isometryoperator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
 
RotationMatrixType toRotationMatrix () const
 

Static Public Member Functions

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

Protected Attributes

Coefficients m_coeffs
 

Detailed Description

template<typename Scalar_, int Options_>
class Eigen::Quaternion< Scalar_, Options_ >

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

Definition/implementation of Quaternion<Scalar> This is defined in the Geometry module.

Template Parameters
Scalar_the scalar type, i.e., the type of the coefficients
Options_controls the memory alignment of the coefficients. 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, quaternions offer the following advantages:

  • compact storage (4 scalars)
  • efficient to compose (28 flops),
  • stable spherical interpolation

The following two typedefs are provided for convenience:

  • Quaternionf for float
  • Quaterniond for double
Warning
Operations interpreting the quaternion as rotation have undefined behavior if the quaternion is not normalized.
See also
class AngleAxis, class Transform

Definition at line 275 of file Quaternion.h.

Member Typedef Documentation

◆ AngleAxisType

template<typename Scalar_ , int Options_>
typedef Base::AngleAxisType Eigen::Quaternion< Scalar_, Options_ >::AngleAxisType

Definition at line 287 of file Quaternion.h.

◆ Base

template<typename Scalar_ , int Options_>
typedef QuaternionBase<Quaternion<Scalar_,Options_> > Eigen::Quaternion< Scalar_, Options_ >::Base

Definition at line 278 of file Quaternion.h.

◆ Coefficients

template<typename Scalar_ , int Options_>
typedef internal::traits<Quaternion>::Coefficients Eigen::Quaternion< Scalar_, Options_ >::Coefficients

Definition at line 286 of file Quaternion.h.

◆ Scalar

template<typename Scalar_ , int Options_>
typedef Scalar_ Eigen::Quaternion< Scalar_, Options_ >::Scalar

Definition at line 281 of file Quaternion.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Scalar_ , int Options_>
anonymous enum

Definition at line 279 of file Quaternion.h.

279 { NeedsAlignment = internal::traits<Quaternion>::Alignment>0 };

Constructor & Destructor Documentation

◆ Quaternion() [1/9]

template<typename Scalar_ , int Options_>
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( )
inline

Default constructor leaving the quaternion uninitialized.

Definition at line 290 of file Quaternion.h.

290 {}

◆ Quaternion() [2/9]

template<typename Scalar_ , int Options_>
Eigen::Quaternion< Scalar_, Options_ >::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 299 of file Quaternion.h.

◆ Quaternion() [3/9]

template<typename Scalar_ , int Options_>
template<typename Derived >
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const Scalar w,
const Eigen::MatrixBase< Derived > &  vec 
)
inline

Constructs and initializes a quaternion from its real part as a scalar, and its imaginary part as a 3-vector [x, y, z]

Definition at line 305 of file Quaternion.h.

306  : m_coeffs(vec.x(), vec.y(), vec.z(), w) {
308  }
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:51
const VectorBlock< const Coefficients, 3 > vec() const
Definition: Quaternion.h:86

◆ Quaternion() [4/9]

template<typename Scalar_ , int Options_>
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const Scalar data)
inlineexplicit

Constructs and initialize a quaternion from the array data

Definition at line 311 of file Quaternion.h.

311 : m_coeffs(data) {}
int data[]

◆ Quaternion() [5/9]

template<typename Scalar_ , int Options_>
template<class Derived >
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const QuaternionBase< Derived > &  other)
inline

Copy constructor

Definition at line 314 of file Quaternion.h.

314 { this->Base::operator=(other); }
QuaternionBase< Quaternion< Scalar_, Options_ > > & operator=(const QuaternionBase< Quaternion< Scalar_, Options_ > > &other)
Definition: Quaternion.h:550

◆ Quaternion() [6/9]

template<typename Scalar_ , int Options_>
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const AngleAxisType aa)
inlineexplicit

Constructs and initializes a quaternion from the angle-axis aa

Definition at line 317 of file Quaternion.h.

317 { *this = aa; }

◆ Quaternion() [7/9]

template<typename Scalar_ , int Options_>
template<typename Derived >
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const MatrixBase< Derived > &  other)
inlineexplicit

Constructs and initializes a quaternion from either:

  • a rotation matrix expression,
  • a 4D vector expression representing quaternion coefficients in the order [x, y, z, w].

Definition at line 324 of file Quaternion.h.

324 { *this = other; }

◆ Quaternion() [8/9]

template<typename Scalar_ , int Options_>
template<typename OtherScalar , int OtherOptions>
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( const Quaternion< OtherScalar, OtherOptions > &  other)
inlineexplicit

Explicit copy constructor with scalar conversion

Definition at line 328 of file Quaternion.h.

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

◆ Quaternion() [9/9]

template<typename Scalar_ , int Options_>
Eigen::Quaternion< Scalar_, Options_ >::Quaternion ( Quaternion< Scalar_, Options_ > &&  other)
inline

Default move constructor

Definition at line 333 of file Quaternion.h.

334  : m_coeffs(std::move(other.coeffs()))
335  {}

Member Function Documentation

◆ coeffs() [1/2]

template<typename Scalar_ , int Options_>
Coefficients& Eigen::Quaternion< Scalar_, Options_ >::coeffs ( )
inline

Definition at line 349 of file Quaternion.h.

349 { return m_coeffs;}

◆ coeffs() [2/2]

template<typename Scalar_ , int Options_>
const Coefficients& Eigen::Quaternion< Scalar_, Options_ >::coeffs ( ) const
inline

Definition at line 350 of file Quaternion.h.

350 { return m_coeffs;}

◆ FromTwoVectors() [1/2]

template<typename Scalar_ , int Options_>
template<typename Derived1 , typename Derived2 >
static Quaternion Eigen::Quaternion< Scalar_, Options_ >::FromTwoVectors ( const MatrixBase< Derived1 > &  a,
const MatrixBase< Derived2 > &  b 
)
static

◆ FromTwoVectors() [2/2]

template<typename Scalar_ , int Options_>
template<typename Derived1 , typename Derived2 >
Quaternion<Scalar,Options> Eigen::Quaternion< Scalar_, Options_ >::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 711 of file Quaternion.h.

712 {
713  Quaternion quat;
714  quat.setFromTwoVectors(a, b);
715  return quat;
716 }
Array< int, 3, 1 > b

◆ operator=()

template<typename Scalar_ , int Options_>
Quaternion& Eigen::Quaternion< Scalar_, Options_ >::operator= ( Quaternion< Scalar_, Options_ > &&  other)
inline

Default move assignment operator

Definition at line 338 of file Quaternion.h.

339  {
340  m_coeffs = std::move(other.coeffs());
341  return *this;
342  }

◆ UnitRandom()

template<typename Scalar , int Options>
Quaternion< Scalar, Options > Eigen::Quaternion< Scalar, Options >::UnitRandom
static
Returns
a random unit quaternion following a uniform distribution law on SO(3)
Note
The implementation is based on http://planning.cs.uiuc.edu/node198.html

Definition at line 685 of file Quaternion.h.

686 {
690  const Scalar u1 = internal::random<Scalar>(0, 1),
691  u2 = internal::random<Scalar>(0, 2*EIGEN_PI),
692  u3 = internal::random<Scalar>(0, 2*EIGEN_PI);
693  const Scalar a = sqrt(Scalar(1) - u1),
694  b = sqrt(u1);
695  return Quaternion (a * sin(u2), a * cos(u2), b * sin(u3), b * cos(u3));
696 }
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1080
#define EIGEN_PI
Definition: MathFunctions.h:16
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cos_op< typename Derived::Scalar >, const Derived > cos(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sin_op< typename Derived::Scalar >, const Derived > sin(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)

Member Data Documentation

◆ m_coeffs

template<typename Scalar_ , int Options_>
Coefficients Eigen::Quaternion< Scalar_, Options_ >::m_coeffs
protected

Definition at line 359 of file Quaternion.h.


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