Eigen/src/Geometry/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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
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_EULERANGLES_H
11 #define EIGEN_EULERANGLES_H
12 
13 namespace Eigen {
14 
35 template<typename Derived>
38 {
42  /* Implemented from Graphics Gems IV */
44 
47 
48  const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
49  const Index i = a0;
50  const Index j = (a0 + 1 + odd)%3;
51  const Index k = (a0 + 2 - odd)%3;
52 
53  if (a0==a2)
54  {
55  res[0] = atan2(coeff(j,i), coeff(k,i));
56  if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0)))
57  {
58  if(res[0] > Scalar(0)) {
59  res[0] -= Scalar(EIGEN_PI);
60  }
61  else {
62  res[0] += Scalar(EIGEN_PI);
63  }
64  Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
65  res[1] = -atan2(s2, coeff(i,i));
66  }
67  else
68  {
69  Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
70  res[1] = atan2(s2, coeff(i,i));
71  }
72 
73  // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles,
74  // we can compute their respective rotation, and apply its inverse to M. Since the result must
75  // be a rotation around x, we have:
76  //
77  // c2 s1.s2 c1.s2 1 0 0
78  // 0 c1 -s1 * M = 0 c3 s3
79  // -s2 s1.c2 c1.c2 0 -s3 c3
80  //
81  // Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3
82 
83  Scalar s1 = sin(res[0]);
84  Scalar c1 = cos(res[0]);
85  res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j));
86  }
87  else
88  {
89  res[0] = atan2(coeff(j,k), coeff(k,k));
90  Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm();
91  if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) {
92  if(res[0] > Scalar(0)) {
93  res[0] -= Scalar(EIGEN_PI);
94  }
95  else {
96  res[0] += Scalar(EIGEN_PI);
97  }
98  res[1] = atan2(-coeff(i,k), -c2);
99  }
100  else
101  res[1] = atan2(-coeff(i,k), c2);
102  Scalar s1 = sin(res[0]);
103  Scalar c1 = cos(res[0]);
104  res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j));
105  }
106  if (!odd)
107  res = -res;
108 
109  return res;
110 }
111 
112 } // end namespace Eigen
113 
114 #endif // EIGEN_EULERANGLES_H
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::atan2
const AutoDiffScalar< Matrix< typename internal::traits< typename internal::remove_all< DerTypeA >::type >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
Definition: AutoDiffScalar.h:654
EIGEN_PI
#define EIGEN_PI
Definition: Eigen/src/Core/MathFunctions.h:16
EIGEN_USING_STD
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1185
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
gtsam::Vector2
Eigen::Vector2d Vector2
Definition: Vector.h:42
Eigen::DenseBase< Solve< Decomposition, RhsType > >::Scalar
internal::traits< Solve< Decomposition, RhsType > >::Scalar Scalar
Definition: DenseBase.h:66
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE
#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS)
Definition: StaticAssert.h:162
res
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Eigen::MatrixBase::eulerAngles
EIGEN_DEVICE_FUNC Matrix< Scalar, 3, 1 > eulerAngles(Index a0, Index a1, Index a2) const
Definition: Eigen/src/Geometry/EulerAngles.h:37
ceres::cos
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:426
c1
static double c1
Definition: airy.c:54
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
align_3::a2
Point2 a2
Definition: testPose2.cpp:770
c2
static double c2
Definition: airy.c:55
Eigen::Matrix< Scalar, 3, 1 >
Eigen::PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
Definition: PlainObjectBase.h:106
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:30