Eigen::EulerAngles< Scalar_, _System > Class Template Reference

Represents a rotation in a 3 dimensional space as three Euler angles. More...

+ Inheritance diagram for Eigen::EulerAngles< Scalar_, _System >:

Public Types

typedef AngleAxis< ScalarAngleAxisType
 
typedef RotationBase< EulerAngles< Scalar_, _System >, 3 > Base
 
typedef Matrix< Scalar, 3, 3 > Matrix3
 
typedef Quaternion< ScalarQuaternionType
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Scalar_ Scalar
 
typedef _System System
 
typedef Matrix< Scalar, 3, 1 > Vector3
 
- Public Types inherited from Eigen::RotationBase< EulerAngles< Scalar_, _System >, 3 >
typedef Matrix< Scalar, Dim, DimRotationMatrixType
 
typedef internal::traits< Derived >::Scalar Scalar
 
typedef Matrix< Scalar, Dim, 1 > VectorType
 

Public Member Functions

Scalaralpha ()
 
Scalar alpha () const
 
Vector3angles ()
 
const Vector3angles () const
 
Scalarbeta ()
 
Scalar beta () const
 
template<typename NewScalarType >
EulerAngles< NewScalarType, Systemcast () const
 
 EulerAngles ()
 
template<typename Derived >
 EulerAngles (const MatrixBase< Derived > &other)
 
template<typename Derived >
 EulerAngles (const RotationBase< Derived, 3 > &rot)
 
 EulerAngles (const Scalar &alpha, const Scalar &beta, const Scalar &gamma)
 
 EulerAngles (const Scalar *data)
 
Scalargamma ()
 
Scalar gamma () const
 
EulerAngles inverse () const
 
bool isApprox (const EulerAngles &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
 operator QuaternionType () const
 
EulerAngles operator- () const
 
template<class Derived >
EulerAnglesoperator= (const MatrixBase< Derived > &other)
 
template<typename Derived >
EulerAnglesoperator= (const RotationBase< Derived, 3 > &rot)
 
Matrix3 toRotationMatrix () const
 
- Public Member Functions inherited from Eigen::RotationBase< EulerAngles< Scalar_, _System >, 3 >
VectorType _transformVector (const OtherVectorType &v) const
 
Derived & derived ()
 
const Derived & derived () const
 
Derived inverse () const
 
RotationMatrixType matrix () const
 
internal::rotation_base_generic_product_selector< Derived, 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, Isometryoperator* (const Translation< Scalar, Dim > &t) const
 
RotationMatrixType operator* (const UniformScaling< Scalar > &s) const
 
RotationMatrixType toRotationMatrix () const
 

Static Public Member Functions

static Vector3 AlphaAxisVector ()
 
static Vector3 BetaAxisVector ()
 
static Vector3 GammaAxisVector ()
 

Private Attributes

Vector3 m_angles
 

Additional Inherited Members

- Public Attributes inherited from Eigen::RotationBase< EulerAngles< Scalar_, _System >, 3 >
 Dim
 

Detailed Description

template<typename Scalar_, class _System>
class Eigen::EulerAngles< Scalar_, _System >

Represents a rotation in a 3 dimensional space as three Euler angles.

Euler rotation is a set of three rotation of three angles over three fixed axes, defined by the EulerSystem given as a template parameter.

Here is how intrinsic Euler angles works:

  • first, rotate the axes system over the alpha axis in angle alpha
  • then, rotate the axes system over the beta axis(which was rotated in the first stage) in angle beta
  • then, rotate the axes system over the gamma axis(which was rotated in the two stages above) in angle gamma
Note
This class support only intrinsic Euler angles for simplicity, see EulerSystem how to easily overcome this for extrinsic systems.

Rotation representation and conversions

It has been proved(see Wikipedia link below) that every rotation can be represented by Euler angles, but there is no single representation (e.g. unlike rotation matrices). Therefore, you can convert from Eigen rotation and to them (including rotation matrices, which is not called "rotations" by Eigen design).

Euler angles usually used for:

  • convenient human representation of rotation, especially in interactive GUI.
  • gimbal systems and robotics
  • efficient encoding(i.e. 3 floats only) of rotation for network protocols.

However, Euler angles are slow comparing to quaternion or matrices, because their unnatural math definition, although it's simple for human. To overcome this, this class provide easy movement from the math friendly representation to the human friendly representation, and vise-versa.

All the user need to do is a safe simple C++ type conversion, and this class take care for the math. Additionally, some axes related computation is done in compile time.

Euler angles ranges in conversions

Rotations representation as EulerAngles are not single (unlike matrices), and even have infinite EulerAngles representations.
For example, add or subtract 2*PI from either angle of EulerAngles and you'll get the same rotation. This is the general reason for infinite representation, but it's not the only general reason for not having a single representation.

When converting rotation to EulerAngles, this class convert it to specific ranges When converting some rotation to EulerAngles, the rules for ranges are as follow:

  • If the rotation we converting from is an EulerAngles (even when it represented as RotationBase explicitly), angles ranges are undefined.
  • otherwise, alpha and gamma angles will be in the range [-PI, PI].
    As for Beta angle:
    • If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2].
    • otherwise:
      • If the beta axis is positive, the beta angle will be in the range [0, PI]
      • If the beta axis is negative, the beta angle will be in the range [-PI, 0]
See also
EulerAngles(const MatrixBase<Derived>&)
EulerAngles(const RotationBase<Derived, 3>&)

Convenient user typedefs

Convenient typedefs for EulerAngles exist for float and double scalar, in a form of EulerAngles{A}{B}{C}{scalar}, e.g. EulerAnglesXYZd, EulerAnglesZYZf.

Only for positive axes{+x,+y,+z} Euler systems are have convenient typedef. If you need negative axes{-x,-y,-z}, it is recommended to create you own typedef with a word that represent what you need.

Example

#include <iostream>
using namespace Eigen;
int main()
{
// A common Euler system by many armies around the world,
// where the first one is the azimuth(the angle from the north -
// the same angle that is show in compass)
// and the second one is elevation(the angle from the horizon)
// and the third one is roll(the angle between the horizontal body
// direction and the plane ground surface)
// Keep remembering we're using radian angles here!
typedef EulerSystem<-EULER_Z, EULER_Y, EULER_X> MyArmySystem;
typedef EulerAngles<double, MyArmySystem> MyArmyAngles;
MyArmyAngles vehicleAngles(
3.14/*PI*/ / 2, /* heading to east, notice that this angle is counter-clockwise */
-0.3, /* going down from a mountain */
0.1); /* slightly rolled to the right */
// Some Euler angles representation that our plane use.
EulerAnglesZYZd planeAngles(0.78474, 0.5271, -0.513794);
MyArmyAngles planeAnglesInMyArmyAngles(planeAngles);
std::cout << "vehicle angles(MyArmy): " << vehicleAngles << std::endl;
std::cout << "plane angles(ZYZ): " << planeAngles << std::endl;
std::cout << "plane angles(MyArmy): " << planeAnglesInMyArmyAngles << std::endl;
// Now lets rotate the plane a little bit
std::cout << "==========================================================\n";
std::cout << "rotating plane now!\n";
std::cout << "==========================================================\n";
Quaterniond planeRotated = AngleAxisd(-0.342, Vector3d::UnitY()) * planeAngles;
planeAngles = planeRotated;
planeAnglesInMyArmyAngles = planeRotated;
std::cout << "new plane angles(ZYZ): " << planeAngles << std::endl;
std::cout << "new plane angles(MyArmy): " << planeAnglesInMyArmyAngles << std::endl;
return 0;
}
int main()
Definition: BVH_Example.cpp:25
static const BasisReturnType UnitY()
EulerAngles< double, EulerSystemZYZ > EulerAnglesZYZd
Definition: EulerAngles.h:323
@ EULER_X
Definition: EulerSystem.h:65
@ EULER_Z
Definition: EulerSystem.h:67
@ EULER_Y
Definition: EulerSystem.h:66
AngleAxis< double > AngleAxisd
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend

Output:

vehicle angles(MyArmy):     1.57 -0.3  0.1
plane angles(ZYZ):          0.78474    0.5271 -0.513794
plane angles(MyArmy):     -0.206273  0.453463 -0.278617
==========================================================
rotating plane now!
==========================================================
new plane angles(ZYZ):      1.44358 0.366507 -1.23637
new plane angles(MyArmy):  -0.18648  0.117896 -0.347841

Additional reading

If you're want to get more idea about how Euler system work in Eigen see EulerSystem.

More information about Euler angles: https://en.wikipedia.org/wiki/Euler_angles

Template Parameters
Scalar_the scalar type, i.e. the type of the angles.
_Systemthe EulerSystem to use, which represents the axes of rotation.

Definition at line 102 of file EulerAngles.h.

Member Typedef Documentation

◆ AngleAxisType

template<typename Scalar_ , class _System >
typedef AngleAxis<Scalar> Eigen::EulerAngles< Scalar_, _System >::AngleAxisType

the equivalent angle-axis type

Definition at line 117 of file EulerAngles.h.

◆ Base

template<typename Scalar_ , class _System >
typedef RotationBase<EulerAngles<Scalar_, _System>, 3> Eigen::EulerAngles< Scalar_, _System >::Base

Definition at line 105 of file EulerAngles.h.

◆ Matrix3

template<typename Scalar_ , class _System >
typedef Matrix<Scalar,3,3> Eigen::EulerAngles< Scalar_, _System >::Matrix3

the equivalent rotation matrix type

Definition at line 114 of file EulerAngles.h.

◆ QuaternionType

template<typename Scalar_ , class _System >
typedef Quaternion<Scalar> Eigen::EulerAngles< Scalar_, _System >::QuaternionType

the equivalent quaternion type

Definition at line 116 of file EulerAngles.h.

◆ RealScalar

template<typename Scalar_ , class _System >
typedef NumTraits<Scalar>::Real Eigen::EulerAngles< Scalar_, _System >::RealScalar

Definition at line 109 of file EulerAngles.h.

◆ Scalar

template<typename Scalar_ , class _System >
typedef Scalar_ Eigen::EulerAngles< Scalar_, _System >::Scalar

the scalar type of the angles

Definition at line 108 of file EulerAngles.h.

◆ System

template<typename Scalar_ , class _System >
typedef _System Eigen::EulerAngles< Scalar_, _System >::System

the EulerSystem to use, which represents the axes of rotation.

Definition at line 112 of file EulerAngles.h.

◆ Vector3

template<typename Scalar_ , class _System >
typedef Matrix<Scalar,3,1> Eigen::EulerAngles< Scalar_, _System >::Vector3

the equivalent 3 dimension vector type

Definition at line 115 of file EulerAngles.h.

Constructor & Destructor Documentation

◆ EulerAngles() [1/5]

template<typename Scalar_ , class _System >
Eigen::EulerAngles< Scalar_, _System >::EulerAngles ( )
inline

Default constructor without initialization.

Definition at line 142 of file EulerAngles.h.

142 {}

◆ EulerAngles() [2/5]

template<typename Scalar_ , class _System >
Eigen::EulerAngles< Scalar_, _System >::EulerAngles ( const Scalar alpha,
const Scalar beta,
const Scalar gamma 
)
inline

Constructs and initialize an EulerAngles (alpha, beta, gamma).

Definition at line 144 of file EulerAngles.h.

144  :
145  m_angles(alpha, beta, gamma) {}
Scalar alpha() const
Definition: EulerAngles.h:200
Scalar gamma() const
Definition: EulerAngles.h:210
Scalar beta() const
Definition: EulerAngles.h:205

◆ EulerAngles() [3/5]

template<typename Scalar_ , class _System >
Eigen::EulerAngles< Scalar_, _System >::EulerAngles ( const Scalar data)
inlineexplicit

Constructs and initialize an EulerAngles from the array data {alpha, beta, gamma}

Definition at line 149 of file EulerAngles.h.

149 : m_angles(data) {}

◆ EulerAngles() [4/5]

template<typename Scalar_ , class _System >
template<typename Derived >
Eigen::EulerAngles< Scalar_, _System >::EulerAngles ( const MatrixBase< Derived > &  other)
inlineexplicit

Constructs and initializes an EulerAngles from either:

  • a 3x3 rotation matrix expression(i.e. pure orthogonal matrix with determinant of +1),
  • a 3D vector expression representing Euler angles.
Note
If other is a 3x3 rotation matrix, the angles range rules will be as follow:
Alpha and gamma angles will be in the range [-PI, PI].
As for Beta angle:
  • If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2].
  • otherwise:
    • If the beta axis is positive, the beta angle will be in the range [0, PI]
    • If the beta axis is negative, the beta angle will be in the range [-PI, 0]

Definition at line 164 of file EulerAngles.h.

164 { *this = other; }

◆ EulerAngles() [5/5]

template<typename Scalar_ , class _System >
template<typename Derived >
Eigen::EulerAngles< Scalar_, _System >::EulerAngles ( const RotationBase< Derived, 3 > &  rot)
inline

Constructs and initialize Euler angles from a rotation rot.

Note
If rot is an EulerAngles (even when it represented as RotationBase explicitly), angles ranges are undefined. Otherwise, alpha and gamma angles will be in the range [-PI, PI].
As for Beta angle:
  • If the system is Tait-Bryan, the beta angle will be in the range [-PI/2, PI/2].
  • otherwise:
    • If the beta axis is positive, the beta angle will be in the range [0, PI]
    • If the beta axis is negative, the beta angle will be in the range [-PI, 0]

Definition at line 178 of file EulerAngles.h.

178 { System::CalcEulerAngles(*this, rot.toRotationMatrix()); }
RotationMatrixType toRotationMatrix() const

Member Function Documentation

◆ alpha() [1/2]

template<typename Scalar_ , class _System >
Scalar& Eigen::EulerAngles< Scalar_, _System >::alpha ( )
inline
Returns
A read-write reference to the angle of the first angle.

Definition at line 202 of file EulerAngles.h.

202 { return m_angles[0]; }

◆ alpha() [2/2]

template<typename Scalar_ , class _System >
Scalar Eigen::EulerAngles< Scalar_, _System >::alpha ( ) const
inline
Returns
The value of the first angle.

Definition at line 200 of file EulerAngles.h.

200 { return m_angles[0]; }

◆ AlphaAxisVector()

template<typename Scalar_ , class _System >
static Vector3 Eigen::EulerAngles< Scalar_, _System >::AlphaAxisVector ( )
inlinestatic
Returns
the axis vector of the first (alpha) rotation

Definition at line 120 of file EulerAngles.h.

120  {
121  const Vector3& u = Vector3::Unit(System::AlphaAxisAbs - 1);
122  return System::IsAlphaOpposite ? -u : u;
123  }
static const BasisReturnType Unit(Index i)
Matrix< Type, 3, 1 > Vector3

◆ angles() [1/2]

template<typename Scalar_ , class _System >
Vector3& Eigen::EulerAngles< Scalar_, _System >::angles ( )
inline
Returns
A read-write reference to the angle values stored in a vector (alpha, beta, gamma).

Definition at line 197 of file EulerAngles.h.

197 { return m_angles; }

◆ angles() [2/2]

template<typename Scalar_ , class _System >
const Vector3& Eigen::EulerAngles< Scalar_, _System >::angles ( ) const
inline
Returns
The angle values stored in a vector (alpha, beta, gamma).

Definition at line 195 of file EulerAngles.h.

195 { return m_angles; }

◆ beta() [1/2]

template<typename Scalar_ , class _System >
Scalar& Eigen::EulerAngles< Scalar_, _System >::beta ( )
inline
Returns
A read-write reference to the angle of the second angle.

Definition at line 207 of file EulerAngles.h.

207 { return m_angles[1]; }

◆ beta() [2/2]

template<typename Scalar_ , class _System >
Scalar Eigen::EulerAngles< Scalar_, _System >::beta ( ) const
inline
Returns
The value of the second angle.

Definition at line 205 of file EulerAngles.h.

205 { return m_angles[1]; }

◆ BetaAxisVector()

template<typename Scalar_ , class _System >
static Vector3 Eigen::EulerAngles< Scalar_, _System >::BetaAxisVector ( )
inlinestatic
Returns
the axis vector of the second (beta) rotation

Definition at line 126 of file EulerAngles.h.

126  {
127  const Vector3& u = Vector3::Unit(System::BetaAxisAbs - 1);
128  return System::IsBetaOpposite ? -u : u;
129  }

◆ cast()

template<typename Scalar_ , class _System >
template<typename NewScalarType >
EulerAngles<NewScalarType, System> Eigen::EulerAngles< Scalar_, _System >::cast ( ) const
inline
Returns
*this with scalar type casted to NewScalarType

Definition at line 294 of file EulerAngles.h.

295  {
296  EulerAngles<NewScalarType, System> e;
297  e.angles() = angles().template cast<NewScalarType>();
298  return e;
299  }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const Vector3 & angles() const
Definition: EulerAngles.h:195

◆ gamma() [1/2]

template<typename Scalar_ , class _System >
Scalar& Eigen::EulerAngles< Scalar_, _System >::gamma ( )
inline
Returns
A read-write reference to the angle of the third angle.

Definition at line 212 of file EulerAngles.h.

212 { return m_angles[2]; }

◆ gamma() [2/2]

template<typename Scalar_ , class _System >
Scalar Eigen::EulerAngles< Scalar_, _System >::gamma ( ) const
inline
Returns
The value of the third angle.

Definition at line 210 of file EulerAngles.h.

210 { return m_angles[2]; }

◆ GammaAxisVector()

template<typename Scalar_ , class _System >
static Vector3 Eigen::EulerAngles< Scalar_, _System >::GammaAxisVector ( )
inlinestatic
Returns
the axis vector of the third (gamma) rotation

Definition at line 132 of file EulerAngles.h.

132  {
133  const Vector3& u = Vector3::Unit(System::GammaAxisAbs - 1);
134  return System::IsGammaOpposite ? -u : u;
135  }

◆ inverse()

template<typename Scalar_ , class _System >
EulerAngles Eigen::EulerAngles< Scalar_, _System >::inverse ( ) const
inline
Returns
The Euler angles rotation inverse (which is as same as the negative), (-alpha, -beta, -gamma).

Definition at line 217 of file EulerAngles.h.

218  {
220  res.m_angles = -m_angles;
221  return res;
222  }
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res

◆ isApprox()

template<typename Scalar_ , class _System >
bool Eigen::EulerAngles< Scalar_, _System >::isApprox ( const EulerAngles< Scalar_, _System > &  other,
const RealScalar 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 266 of file EulerAngles.h.

268  { return angles().isApprox(other.angles(), prec); }

◆ operator QuaternionType()

template<typename Scalar_ , class _System >
Eigen::EulerAngles< Scalar_, _System >::operator QuaternionType ( ) const
inline

Convert the Euler angles to quaternion.

Definition at line 278 of file EulerAngles.h.

279  {
280  return
284  }
static Vector3 GammaAxisVector()
Definition: EulerAngles.h:132
static Vector3 AlphaAxisVector()
Definition: EulerAngles.h:120
AngleAxis< Scalar > AngleAxisType
Definition: EulerAngles.h:117
static Vector3 BetaAxisVector()
Definition: EulerAngles.h:126

◆ operator-()

template<typename Scalar_ , class _System >
EulerAngles Eigen::EulerAngles< Scalar_, _System >::operator- ( ) const
inline
Returns
The Euler angles rotation negative (which is as same as the inverse), (-alpha, -beta, -gamma).

Definition at line 227 of file EulerAngles.h.

228  {
229  return inverse();
230  }
EulerAngles inverse() const
Definition: EulerAngles.h:217

◆ operator=() [1/2]

template<typename Scalar_ , class _System >
template<class Derived >
EulerAngles& Eigen::EulerAngles< Scalar_, _System >::operator= ( const MatrixBase< Derived > &  other)
inline

Set *this from either:

  • a 3x3 rotation matrix expression(i.e. pure orthogonal matrix with determinant of +1),
  • a 3D vector expression representing Euler angles.

See EulerAngles(const MatrixBase<Derived, 3>&) for more information about angles ranges output.

Definition at line 240 of file EulerAngles.h.

241  {
242  EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename Derived::Scalar>::value),
243  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
244 
245  internal::eulerangles_assign_impl<System, Derived>::run(*this, other.derived());
246  return *this;
247  }
#define EIGEN_STATIC_ASSERT(X, MSG)

◆ operator=() [2/2]

template<typename Scalar_ , class _System >
template<typename Derived >
EulerAngles& Eigen::EulerAngles< Scalar_, _System >::operator= ( const RotationBase< Derived, 3 > &  rot)
inline

Set *this from a rotation.

See EulerAngles(const RotationBase<Derived, 3>&) for more information about angles ranges output.

Definition at line 257 of file EulerAngles.h.

257  {
258  System::CalcEulerAngles(*this, rot.toRotationMatrix());
259  return *this;
260  }

◆ toRotationMatrix()

template<typename Scalar_ , class _System >
Matrix3 Eigen::EulerAngles< Scalar_, _System >::toRotationMatrix ( ) const
inline
Returns
an equivalent 3x3 rotation matrix.

Definition at line 271 of file EulerAngles.h.

272  {
273  // TODO: Calc it faster
274  return static_cast<QuaternionType>(*this).toRotationMatrix();
275  }
Quaternion< Scalar > QuaternionType
Definition: EulerAngles.h:116

Member Data Documentation

◆ m_angles

template<typename Scalar_ , class _System >
Vector3 Eigen::EulerAngles< Scalar_, _System >::m_angles
private

Definition at line 138 of file EulerAngles.h.


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