unsupported/Eigen/src/EulerAngles/EulerAngles.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2015 Tal Hadad <tal_hd@hotmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_EULERANGLESCLASS_H// TODO: Fix previous "EIGEN_EULERANGLES_H" definition?
11 #define EIGEN_EULERANGLESCLASS_H
12 
13 namespace Eigen
14 {
99  template <typename _Scalar, class _System>
100  class EulerAngles : public RotationBase<EulerAngles<_Scalar, _System>, 3>
101  {
102  public:
104 
106  typedef _Scalar Scalar;
108 
110  typedef _System System;
111 
118  static Vector3 AlphaAxisVector() {
119  const Vector3& u = Vector3::Unit(System::AlphaAxisAbs - 1);
120  return System::IsAlphaOpposite ? -u : u;
121  }
122 
124  static Vector3 BetaAxisVector() {
125  const Vector3& u = Vector3::Unit(System::BetaAxisAbs - 1);
126  return System::IsBetaOpposite ? -u : u;
127  }
128 
130  static Vector3 GammaAxisVector() {
131  const Vector3& u = Vector3::Unit(System::GammaAxisAbs - 1);
132  return System::IsGammaOpposite ? -u : u;
133  }
134 
135  private:
136  Vector3 m_angles;
137 
138  public:
142  EulerAngles(const Scalar& alpha, const Scalar& beta, const Scalar& gamma) :
143  m_angles(alpha, beta, gamma) {}
144 
145  // TODO: Test this constructor
147  explicit EulerAngles(const Scalar* data) : m_angles(data) {}
148 
161  template<typename Derived>
162  explicit EulerAngles(const MatrixBase<Derived>& other) { *this = other; }
163 
175  template<typename Derived>
176  EulerAngles(const RotationBase<Derived, 3>& rot) { System::CalcEulerAngles(*this, rot.toRotationMatrix()); }
177 
178  /*EulerAngles(const QuaternionType& q)
179  {
180  // TODO: Implement it in a faster way for quaternions
181  // According to http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
182  // we can compute only the needed matrix cells and then convert to euler angles. (see ZYX example below)
183  // Currently we compute all matrix cells from quaternion.
184 
185  // Special case only for ZYX
186  //Scalar y2 = q.y() * q.y();
187  //m_angles[0] = std::atan2(2*(q.w()*q.z() + q.x()*q.y()), (1 - 2*(y2 + q.z()*q.z())));
188  //m_angles[1] = std::asin( 2*(q.w()*q.y() - q.z()*q.x()));
189  //m_angles[2] = std::atan2(2*(q.w()*q.x() + q.y()*q.z()), (1 - 2*(q.x()*q.x() + y2)));
190  }*/
191 
193  const Vector3& angles() const { return m_angles; }
195  Vector3& angles() { return m_angles; }
196 
198  Scalar alpha() const { return m_angles[0]; }
200  Scalar& alpha() { return m_angles[0]; }
201 
203  Scalar beta() const { return m_angles[1]; }
205  Scalar& beta() { return m_angles[1]; }
206 
208  Scalar gamma() const { return m_angles[2]; }
210  Scalar& gamma() { return m_angles[2]; }
211 
216  {
218  res.m_angles = -m_angles;
219  return res;
220  }
221 
226  {
227  return inverse();
228  }
229 
237  template<class Derived>
239  {
241  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
242 
244  return *this;
245  }
246 
247  // TODO: Assign and construct from another EulerAngles (with different system)
248 
254  template<typename Derived>
256  System::CalcEulerAngles(*this, rot.toRotationMatrix());
257  return *this;
258  }
259 
265  const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const
266  { return angles().isApprox(other.angles(), prec); }
267 
269  Matrix3 toRotationMatrix() const
270  {
271  // TODO: Calc it faster
272  return static_cast<QuaternionType>(*this).toRotationMatrix();
273  }
274 
276  operator QuaternionType() const
277  {
278  return
282  }
283 
284  friend std::ostream& operator<<(std::ostream& s, const EulerAngles<Scalar, System>& eulerAngles)
285  {
286  s << eulerAngles.angles().transpose();
287  return s;
288  }
289 
291  template <typename NewScalarType>
293  {
295  e.angles() = angles().template cast<NewScalarType>();
296  return e;
297  }
298  };
299 
300 #define EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(AXES, SCALAR_TYPE, SCALAR_POSTFIX) \
301  \
302  typedef EulerAngles<SCALAR_TYPE, EulerSystem##AXES> EulerAngles##AXES##SCALAR_POSTFIX;
303 
304 #define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX) \
305  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYZ, SCALAR_TYPE, SCALAR_POSTFIX) \
306  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYX, SCALAR_TYPE, SCALAR_POSTFIX) \
307  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZY, SCALAR_TYPE, SCALAR_POSTFIX) \
308  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZX, SCALAR_TYPE, SCALAR_POSTFIX) \
309  \
310  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZX, SCALAR_TYPE, SCALAR_POSTFIX) \
311  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZY, SCALAR_TYPE, SCALAR_POSTFIX) \
312  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
313  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXY, SCALAR_TYPE, SCALAR_POSTFIX) \
314  \
315  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXY, SCALAR_TYPE, SCALAR_POSTFIX) \
316  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
317  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYX, SCALAR_TYPE, SCALAR_POSTFIX) \
318  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYZ, SCALAR_TYPE, SCALAR_POSTFIX)
319 
322 
323  namespace internal
324  {
325  template<typename _Scalar, class _System>
326  struct traits<EulerAngles<_Scalar, _System> >
327  {
328  typedef _Scalar Scalar;
329  };
330 
331  // set from a rotation matrix
332  template<class System, class Other>
333  struct eulerangles_assign_impl<System,Other,3,3>
334  {
335  typedef typename Other::Scalar Scalar;
336  static void run(EulerAngles<Scalar, System>& e, const Other& m)
337  {
338  System::CalcEulerAngles(e, m);
339  }
340  };
341 
342  // set from a vector of Euler angles
343  template<class System, class Other>
344  struct eulerangles_assign_impl<System,Other,3,1>
345  {
346  typedef typename Other::Scalar Scalar;
347  static void run(EulerAngles<Scalar, System>& e, const Other& vec)
348  {
349  e.angles() = vec;
350  }
351  };
352  }
353 }
354 
355 #endif // EIGEN_EULERANGLESCLASS_H
Matrix3f m
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
SCALAR Scalar
Definition: bench_gemm.cpp:46
EulerAngles(const RotationBase< Derived, 3 > &rot)
EulerAngles & operator=(const MatrixBase< Derived > &other)
EulerAngles & operator=(const RotationBase< Derived, 3 > &rot)
EulerAngles(const MatrixBase< Derived > &other)
bool isApprox(const EulerAngles &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
RotationBase< EulerAngles< _Scalar, _System >, 3 > Base
int data[]
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Common base class for compact rotation representations.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Represents a rotation in a 3 dimensional space as three Euler angles.
EIGEN_DEVICE_FUNC RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:45
#define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX)
EulerAngles(const Scalar &alpha, const Scalar &beta, const Scalar &gamma)
The quaternion class used to represent 3D orientations and rotations.
The matrix class, also used for vectors and row-vectors.
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
EulerAngles< NewScalarType, System > cast() const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:12