Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_EULERANGLES_H
00011 #define EIGEN_EULERANGLES_H
00012
00013 namespace Eigen {
00014
00035 template<typename Derived>
00036 inline Matrix<typename MatrixBase<Derived>::Scalar,3,1>
00037 MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
00038 {
00039 using std::atan2;
00040 using std::sin;
00041 using std::cos;
00042
00043 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)
00044
00045 Matrix<Scalar,3,1> res;
00046 typedef Matrix<typename Derived::Scalar,2,1> Vector2;
00047
00048 const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
00049 const Index i = a0;
00050 const Index j = (a0 + 1 + odd)%3;
00051 const Index k = (a0 + 2 - odd)%3;
00052
00053 if (a0==a2)
00054 {
00055 res[0] = atan2(coeff(j,i), coeff(k,i));
00056 if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0)))
00057 {
00058 res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
00059 Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
00060 res[1] = -atan2(s2, coeff(i,i));
00061 }
00062 else
00063 {
00064 Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
00065 res[1] = atan2(s2, coeff(i,i));
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 Scalar s1 = sin(res[0]);
00079 Scalar c1 = cos(res[0]);
00080 res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j));
00081 }
00082 else
00083 {
00084 res[0] = atan2(coeff(j,k), coeff(k,k));
00085 Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm();
00086 if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) {
00087 res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
00088 res[1] = atan2(-coeff(i,k), -c2);
00089 }
00090 else
00091 res[1] = atan2(-coeff(i,k), c2);
00092 Scalar s1 = sin(res[0]);
00093 Scalar c1 = cos(res[0]);
00094 res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j));
00095 }
00096 if (!odd)
00097 res = -res;
00098
00099 return res;
00100 }
00101
00102 }
00103
00104 #endif // EIGEN_EULERANGLES_H