2008-12-05 15:56:28 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-12-05 15:56:28 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-12-05 15:56:28 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-12-05 15:56:28 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_EULERANGLES_H
|
|
|
|
|
#define EIGEN_EULERANGLES_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2009-01-29 23:10:16 +00:00
|
|
|
/** \geometry_module \ingroup Geometry_Module
|
2010-06-29 10:10:47 -04:00
|
|
|
*
|
2008-12-05 15:56:28 +00:00
|
|
|
*
|
|
|
|
|
* \returns the Euler-angles of the rotation matrix \c *this using the convention defined by the triplet (\a a0,\a a1,\a a2)
|
|
|
|
|
*
|
|
|
|
|
* Each of the three parameters \a a0,\a a1,\a a2 represents the respective rotation axis as an integer in {0,1,2}.
|
|
|
|
|
* For instance, in:
|
|
|
|
|
* \code Vector3f ea = mat.eulerAngles(2, 0, 2); \endcode
|
|
|
|
|
* "2" represents the z axis and "0" the x axis, etc. The returned angles are such that
|
|
|
|
|
* we have the following equality:
|
|
|
|
|
* \code
|
|
|
|
|
* mat == AngleAxisf(ea[0], Vector3f::UnitZ())
|
|
|
|
|
* * AngleAxisf(ea[1], Vector3f::UnitX())
|
|
|
|
|
* * AngleAxisf(ea[2], Vector3f::UnitZ()); \endcode
|
|
|
|
|
* This corresponds to the right-multiply conventions (with right hand side frames).
|
|
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
inline Matrix<typename MatrixBase<Derived>::Scalar,3,1>
|
2010-05-30 16:00:58 -04:00
|
|
|
MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
|
2008-12-05 15:56:28 +00:00
|
|
|
{
|
2012-11-06 15:25:50 +01:00
|
|
|
using std::atan2;
|
2008-12-06 11:04:33 +00:00
|
|
|
/* Implemented from Graphics Gems IV */
|
2008-12-05 15:56:28 +00:00
|
|
|
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)
|
|
|
|
|
|
|
|
|
|
Matrix<Scalar,3,1> res;
|
|
|
|
|
typedef Matrix<typename Derived::Scalar,2,1> Vector2;
|
2010-02-10 10:52:28 +01:00
|
|
|
const Scalar epsilon = NumTraits<Scalar>::dummy_precision();
|
2008-12-05 15:56:28 +00:00
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
|
|
|
|
|
const Index i = a0;
|
|
|
|
|
const Index j = (a0 + 1 + odd)%3;
|
|
|
|
|
const Index k = (a0 + 2 - odd)%3;
|
2008-12-05 15:56:28 +00:00
|
|
|
|
|
|
|
|
if (a0==a2)
|
|
|
|
|
{
|
|
|
|
|
Scalar s = Vector2(coeff(j,i) , coeff(k,i)).norm();
|
2012-11-06 15:25:50 +01:00
|
|
|
res[1] = atan2(s, coeff(i,i));
|
2008-12-05 15:56:28 +00:00
|
|
|
if (s > epsilon)
|
|
|
|
|
{
|
2012-11-06 15:25:50 +01:00
|
|
|
res[0] = atan2(coeff(j,i), coeff(k,i));
|
|
|
|
|
res[2] = atan2(coeff(i,j),-coeff(i,k));
|
2008-12-05 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res[0] = Scalar(0);
|
2012-11-06 15:25:50 +01:00
|
|
|
res[2] = (coeff(i,i)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j));
|
2008-12-05 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Scalar c = Vector2(coeff(i,i) , coeff(i,j)).norm();
|
2012-11-06 15:25:50 +01:00
|
|
|
res[1] = atan2(-coeff(i,k), c);
|
2008-12-05 15:56:28 +00:00
|
|
|
if (c > epsilon)
|
|
|
|
|
{
|
2012-11-06 15:25:50 +01:00
|
|
|
res[0] = atan2(coeff(j,k), coeff(k,k));
|
|
|
|
|
res[2] = atan2(coeff(i,j), coeff(i,i));
|
2008-12-05 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res[0] = Scalar(0);
|
2012-11-06 15:25:50 +01:00
|
|
|
res[2] = (coeff(i,k)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j));
|
2008-12-05 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!odd)
|
|
|
|
|
res = -res;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
2008-12-05 15:56:28 +00:00
|
|
|
|
|
|
|
|
#endif // EIGEN_EULERANGLES_H
|