Eigen::AngleAxis< Scalar_ > Class Template Reference

Represents a 3D rotation as a rotation angle around an arbitrary 3D axis. More...

+ Inheritance diagram for Eigen::AngleAxis< Scalar_ >:

Public Types

enum  { Dim }
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef Quaternion< ScalarQuaternionType
 
typedef Scalar_ Scalar
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
- Public Types inherited from Eigen::RotationBase< AngleAxis< Scalar_ >, 3 >
enum  
 
typedef Matrix< Scalar, Dim, DimRotationMatrixType
 
typedef internal::traits< AngleAxis< Scalar_ > >::Scalar Scalar
 
typedef Matrix< Scalar, Dim, 1 > VectorType
 

Public Member Functions

Scalarangle ()
 
Scalar angle () const
 
 AngleAxis ()
 
template<typename OtherScalarType >
 AngleAxis (const AngleAxis< OtherScalarType > &other)
 
template<typename Derived >
 AngleAxis (const MatrixBase< Derived > &m)
 
template<typename QuatDerived >
 AngleAxis (const QuaternionBase< QuatDerived > &q)
 
template<typename Derived >
 AngleAxis (const Scalar &angle, const MatrixBase< Derived > &axis)
 
Vector3axis ()
 
const Vector3axis () const
 
template<typename NewScalarType >
internal::cast_return_type< AngleAxis, AngleAxis< NewScalarType > >::type cast () const
 
template<typename Derived >
AngleAxisfromRotationMatrix (const MatrixBase< Derived > &m)
 
template<typename Derived >
AngleAxis< Scalar > & fromRotationMatrix (const MatrixBase< Derived > &mat)
 Sets *this from a 3x3 rotation matrix. More...
 
AngleAxis inverse () const
 
bool isApprox (const AngleAxis &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
 
QuaternionType operator* (const AngleAxis &other) const
 
QuaternionType operator* (const QuaternionType &other) const
 
template<typename Derived >
AngleAxisoperator= (const MatrixBase< Derived > &m)
 
template<typename Derived >
AngleAxis< Scalar > & operator= (const MatrixBase< Derived > &mat)
 
template<class QuatDerived >
AngleAxisoperator= (const QuaternionBase< QuatDerived > &q)
 
template<typename QuatDerived >
AngleAxis< Scalar > & operator= (const QuaternionBase< QuatDerived > &q)
 
Matrix3 toRotationMatrix (void) const
 
- Public Member Functions inherited from Eigen::RotationBase< AngleAxis< Scalar_ >, 3 >
VectorType _transformVector (const OtherVectorType &v) const
 
AngleAxis< Scalar_ > & derived ()
 
const AngleAxis< Scalar_ > & derived () const
 
AngleAxis< Scalar_ > inverse () const
 
RotationMatrixType matrix () const
 
internal::rotation_base_generic_product_selector< AngleAxis< Scalar_ >, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator* (const EigenBase< OtherDerived > &e) const
 
Transform< Scalar, Dim, Mode > operator* (const Transform< Scalar, Dim, Mode, Options > &t) const
 
Transform< Scalar, Dim, Isometry > operator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
 
RotationMatrixType toRotationMatrix () const
 

Static Public Member Functions

static const AngleAxis Identity ()
 

Protected Attributes

Scalar m_angle
 
Vector3 m_axis
 

Private Types

typedef RotationBase< AngleAxis< Scalar_ >, 3 > Base
 

Detailed Description

template<typename Scalar_>
class Eigen::AngleAxis< Scalar_ >

Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.

This is defined in the Geometry module.

Parameters
Scalar_the scalar type, i.e., the type of the coefficients.
Warning
When setting up an AngleAxis object, the axis vector must be normalized.

The following two typedefs are provided for convenience:

  • AngleAxisf for float
  • AngleAxisd for double

Combined with MatrixBase::Unit{X,Y,Z}, AngleAxis can be used to easily mimic Euler-angles. Here is an example:

m = AngleAxisf(0.25*M_PI, Vector3f::UnitX())
* AngleAxisf(0.5*M_PI, Vector3f::UnitY())
* AngleAxisf(0.33*M_PI, Vector3f::UnitZ());
cout << m << endl << "is unitary: " << m.isUnitary() << endl;
Matrix3f m
static const BasisReturnType UnitY()
static const BasisReturnType UnitX()
static const BasisReturnType UnitZ()
AngleAxis< float > AngleAxisf
Definition: AngleAxis.h:159
Matrix< float, 3, 3 > Matrix3f
3×3 matrix of type float.
Definition: Matrix.h:501

Output:

1.19e-07        0        1
   0.969   -0.249        0
   0.249    0.969 1.19e-07
is unitary: 1
Note
This class is not aimed to be used to store a rotation transformation, but rather to make easier the creation of other rotation (Quaternion, rotation Matrix) and transformation objects.
See also
class Quaternion, class Transform, MatrixBase::UnitX()

Definition at line 51 of file AngleAxis.h.

Member Typedef Documentation

◆ Base

template<typename Scalar_ >
typedef RotationBase<AngleAxis<Scalar_>,3> Eigen::AngleAxis< Scalar_ >::Base
private

Definition at line 53 of file AngleAxis.h.

◆ Matrix3

template<typename Scalar_ >
typedef Matrix<Scalar,3,3> Eigen::AngleAxis< Scalar_ >::Matrix3

Definition at line 62 of file AngleAxis.h.

◆ QuaternionType

template<typename Scalar_ >
typedef Quaternion<Scalar> Eigen::AngleAxis< Scalar_ >::QuaternionType

Definition at line 64 of file AngleAxis.h.

◆ Scalar

template<typename Scalar_ >
typedef Scalar_ Eigen::AngleAxis< Scalar_ >::Scalar

the scalar type of the coefficients

Definition at line 61 of file AngleAxis.h.

◆ Vector3

template<typename Scalar_ >
typedef Matrix<Scalar,3,1> Eigen::AngleAxis< Scalar_ >::Vector3

Definition at line 63 of file AngleAxis.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Scalar_ >
anonymous enum
Enumerator
Dim 

Definition at line 59 of file AngleAxis.h.

59 { Dim = 3 };

Constructor & Destructor Documentation

◆ AngleAxis() [1/5]

template<typename Scalar_ >
Eigen::AngleAxis< Scalar_ >::AngleAxis ( )
inline

Default constructor without initialization.

Definition at line 74 of file AngleAxis.h.

74 {}

◆ AngleAxis() [2/5]

template<typename Scalar_ >
template<typename Derived >
Eigen::AngleAxis< Scalar_ >::AngleAxis ( const Scalar angle,
const MatrixBase< Derived > &  axis 
)
inline

Constructs and initialize the angle-axis rotation from an angle in radian and an axis which must be normalized.

Warning
If the axis vector is not normalized, then the angle-axis object represents an invalid rotation.

Definition at line 82 of file AngleAxis.h.

82 : m_axis(axis), m_angle(angle) {}
const Vector3 & axis() const
Definition: AngleAxis.h:98
Vector3 m_axis
Definition: AngleAxis.h:68
Scalar angle() const
Definition: AngleAxis.h:93
Scalar m_angle
Definition: AngleAxis.h:69

◆ AngleAxis() [3/5]

template<typename Scalar_ >
template<typename QuatDerived >
Eigen::AngleAxis< Scalar_ >::AngleAxis ( const QuaternionBase< QuatDerived > &  q)
inlineexplicit

Constructs and initialize the angle-axis rotation from a quaternion q. This function implicitly normalizes the quaternion q.

Definition at line 87 of file AngleAxis.h.

87 { *this = q; }

◆ AngleAxis() [4/5]

template<typename Scalar_ >
template<typename Derived >
Eigen::AngleAxis< Scalar_ >::AngleAxis ( const MatrixBase< Derived > &  m)
inlineexplicit

Constructs and initialize the angle-axis rotation from a 3x3 rotation matrix.

Definition at line 90 of file AngleAxis.h.

90 { *this = m; }

◆ AngleAxis() [5/5]

template<typename Scalar_ >
template<typename OtherScalarType >
Eigen::AngleAxis< Scalar_ >::AngleAxis ( const AngleAxis< OtherScalarType > &  other)
inlineexplicit

Copy constructor with scalar type conversion

Definition at line 141 of file AngleAxis.h.

142  {
143  m_axis = other.axis().template cast<Scalar>();
144  m_angle = Scalar(other.angle());
145  }
Scalar_ Scalar
Definition: AngleAxis.h:61

Member Function Documentation

◆ angle() [1/2]

template<typename Scalar_ >
Scalar& Eigen::AngleAxis< Scalar_ >::angle ( )
inline
Returns
a read-write reference to the stored angle in radian

Definition at line 95 of file AngleAxis.h.

95 { return m_angle; }

◆ angle() [2/2]

template<typename Scalar_ >
Scalar Eigen::AngleAxis< Scalar_ >::angle ( ) const
inline
Returns
the value of the rotation angle in radian

Definition at line 93 of file AngleAxis.h.

93 { return m_angle; }

◆ axis() [1/2]

template<typename Scalar_ >
Vector3& Eigen::AngleAxis< Scalar_ >::axis ( )
inline
Returns
a read-write reference to the stored rotation axis.
Warning
The rotation axis must remain a unit vector.

Definition at line 103 of file AngleAxis.h.

103 { return m_axis; }

◆ axis() [2/2]

template<typename Scalar_ >
const Vector3& Eigen::AngleAxis< Scalar_ >::axis ( ) const
inline
Returns
the rotation axis

Definition at line 98 of file AngleAxis.h.

98 { return m_axis; }

◆ cast()

template<typename Scalar_ >
template<typename NewScalarType >
internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type Eigen::AngleAxis< 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 136 of file AngleAxis.h.

137  { return typename internal::cast_return_type<AngleAxis,AngleAxis<NewScalarType> >::type(*this); }

◆ fromRotationMatrix() [1/2]

template<typename Scalar_ >
template<typename Derived >
AngleAxis& Eigen::AngleAxis< Scalar_ >::fromRotationMatrix ( const MatrixBase< Derived > &  m)

◆ fromRotationMatrix() [2/2]

template<typename Scalar_ >
template<typename Derived >
AngleAxis<Scalar>& Eigen::AngleAxis< Scalar_ >::fromRotationMatrix ( const MatrixBase< Derived > &  mat)

Sets *this from a 3x3 rotation matrix.

Definition at line 211 of file AngleAxis.h.

212 {
213  return *this = QuaternionType(mat);
214 }
Quaternion< Scalar > QuaternionType
Definition: AngleAxis.h:64

◆ Identity()

template<typename Scalar_ >
static const AngleAxis Eigen::AngleAxis< Scalar_ >::Identity ( )
inlinestatic

Definition at line 147 of file AngleAxis.h.

147 { return AngleAxis(Scalar(0), Vector3::UnitX()); }

◆ inverse()

template<typename Scalar_ >
AngleAxis Eigen::AngleAxis< Scalar_ >::inverse ( ) const
inline
Returns
the inverse rotation, i.e., an angle-axis with opposite rotation angle

Definition at line 118 of file AngleAxis.h.

119  { return AngleAxis(-m_angle, m_axis); }

◆ isApprox()

template<typename Scalar_ >
bool Eigen::AngleAxis< Scalar_ >::isApprox ( const AngleAxis< Scalar_ > &  other,
const typename NumTraits< Scalar >::Real &  prec = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
true if *this is approximately equal to other, within the precision determined by prec.
See also
MatrixBase::isApprox()

Definition at line 153 of file AngleAxis.h.

154  { return m_axis.isApprox(other.m_axis, prec) && internal::isApprox(m_angle,other.m_angle, prec); }
bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())

◆ operator*() [1/2]

template<typename Scalar_ >
QuaternionType Eigen::AngleAxis< Scalar_ >::operator* ( const AngleAxis< Scalar_ > &  other) const
inline

Concatenates two rotations

Definition at line 106 of file AngleAxis.h.

107  { return QuaternionType(*this) * QuaternionType(other); }

◆ operator*() [2/2]

template<typename Scalar_ >
QuaternionType Eigen::AngleAxis< Scalar_ >::operator* ( const QuaternionType other) const
inline

Concatenates two rotations

Definition at line 110 of file AngleAxis.h.

111  { return QuaternionType(*this) * other; }

◆ operator=() [1/4]

template<typename Scalar_ >
template<typename Derived >
AngleAxis& Eigen::AngleAxis< Scalar_ >::operator= ( const MatrixBase< Derived > &  m)

◆ operator=() [2/4]

template<typename Scalar_ >
template<typename Derived >
AngleAxis<Scalar>& Eigen::AngleAxis< Scalar_ >::operator= ( const MatrixBase< Derived > &  mat)

Set *this from a 3x3 rotation matrix mat.

Definition at line 199 of file AngleAxis.h.

200 {
201  // Since a direct conversion would not be really faster,
202  // let's use the robust Quaternion implementation:
203  return *this = QuaternionType(mat);
204 }

◆ operator=() [3/4]

template<typename Scalar_ >
template<class QuatDerived >
AngleAxis& Eigen::AngleAxis< Scalar_ >::operator= ( const QuaternionBase< QuatDerived > &  q)

◆ operator=() [4/4]

template<typename Scalar_ >
template<typename QuatDerived >
AngleAxis<Scalar>& Eigen::AngleAxis< Scalar_ >::operator= ( const QuaternionBase< QuatDerived > &  q)

Set *this from a unit quaternion.

The resulting axis is normalized, and the computed angle is in the [0,pi] range.

This function implicitly normalizes the quaternion q.

Definition at line 172 of file AngleAxis.h.

173 {
176  Scalar n = q.vec().norm();
177  if(n<NumTraits<Scalar>::epsilon())
178  n = q.vec().stableNorm();
179 
180  if (n != Scalar(0))
181  {
182  m_angle = Scalar(2)*atan2(n, abs(q.w()));
183  if(q.w() < Scalar(0))
184  n = -n;
185  m_axis = q.vec() / n;
186  }
187  else
188  {
189  m_angle = Scalar(0);
190  m_axis << Scalar(1), Scalar(0), Scalar(0);
191  }
192  return *this;
193 }
const CwiseBinaryOp< atan2< Scalar >, const Derived, const OtherDerived > atan2(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
int n
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1080
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)

◆ toRotationMatrix()

template<typename Scalar >
AngleAxis< Scalar >::Matrix3 Eigen::AngleAxis< Scalar >::toRotationMatrix ( void  ) const

Constructs and

Returns
an equivalent 3x3 rotation matrix.

Definition at line 220 of file AngleAxis.h.

221 {
224  Matrix3 res;
225  Vector3 sin_axis = sin(m_angle) * m_axis;
226  Scalar c = cos(m_angle);
227  Vector3 cos1_axis = (Scalar(1)-c) * m_axis;
228 
229  Scalar tmp;
230  tmp = cos1_axis.x() * m_axis.y();
231  res.coeffRef(0,1) = tmp - sin_axis.z();
232  res.coeffRef(1,0) = tmp + sin_axis.z();
233 
234  tmp = cos1_axis.x() * m_axis.z();
235  res.coeffRef(0,2) = tmp + sin_axis.y();
236  res.coeffRef(2,0) = tmp - sin_axis.y();
237 
238  tmp = cos1_axis.y() * m_axis.z();
239  res.coeffRef(1,2) = tmp - sin_axis.x();
240  res.coeffRef(2,1) = tmp + sin_axis.x();
241 
242  res.diagonal() = (cos1_axis.cwiseProduct(m_axis)).array() + c;
243 
244  return res;
245 }
Array33i c
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Matrix< Scalar, 3, 1 > Vector3
Definition: AngleAxis.h:63
Matrix< Scalar, 3, 3 > Matrix3
Definition: AngleAxis.h:62
std::array< T, N > array
Definition: EmulateArray.h:256
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)

Member Data Documentation

◆ m_angle

template<typename Scalar_ >
Scalar Eigen::AngleAxis< Scalar_ >::m_angle
protected

Definition at line 69 of file AngleAxis.h.

◆ m_axis

template<typename Scalar_ >
Vector3 Eigen::AngleAxis< Scalar_ >::m_axis
protected

Definition at line 68 of file AngleAxis.h.


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