1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra. Eigen itself is part of the KDE project.
4
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
25
#ifndef EIGEN_ROTATIONBASE_H
26
#define EIGEN_ROTATIONBASE_H
28
// this file aims to contains the various representations of rotation/orientation
29
// in 2D and 3D space excepted Matrix and Quaternion.
31
/** \class RotationBase
33
* \brief Common base class for compact rotation representations
35
* \param Derived is the derived type, i.e., a rotation type
36
* \param _Dim the dimension of the space
38
template<typename Derived, int _Dim>
43
/** the scalar type of the coefficients */
44
typedef typename ei_traits<Derived>::Scalar Scalar;
46
/** corresponding linear transformation matrix type */
47
typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
49
inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
50
inline Derived& derived() { return *static_cast<Derived*>(this); }
52
/** \returns an equivalent rotation matrix */
53
inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
55
/** \returns the inverse rotation */
56
inline Derived inverse() const { return derived().inverse(); }
58
/** \returns the concatenation of the rotation \c *this with a translation \a t */
59
inline Transform<Scalar,Dim> operator*(const Translation<Scalar,Dim>& t) const
60
{ return toRotationMatrix() * t; }
62
/** \returns the concatenation of the rotation \c *this with a scaling \a s */
63
inline RotationMatrixType operator*(const Scaling<Scalar,Dim>& s) const
64
{ return toRotationMatrix() * s; }
66
/** \returns the concatenation of the rotation \c *this with an affine transformation \a t */
67
inline Transform<Scalar,Dim> operator*(const Transform<Scalar,Dim>& t) const
68
{ return toRotationMatrix() * t; }
73
* Constructs a Dim x Dim rotation matrix from the rotation \a r
75
template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
76
template<typename OtherDerived>
77
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
78
::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
80
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
81
*this = r.toRotationMatrix();
86
* Set a Dim x Dim rotation matrix from the rotation \a r
88
template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
89
template<typename OtherDerived>
90
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>&
91
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
92
::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
94
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
95
return *this = r.toRotationMatrix();
100
* Helper function to return an arbitrary rotation object to a rotation matrix.
102
* \param Scalar the numeric type of the matrix coefficients
103
* \param Dim the dimension of the current space
105
* It returns a Dim x Dim fixed size matrix.
107
* Default specializations are provided for:
108
* - any scalar type (2D),
109
* - any matrix expression,
110
* - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D)
112
* Currently ei_toRotationMatrix is only used by Transform.
114
* \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis
116
template<typename Scalar, int Dim>
117
inline static Matrix<Scalar,2,2> ei_toRotationMatrix(const Scalar& s)
119
EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
120
return Rotation2D<Scalar>(s).toRotationMatrix();
123
template<typename Scalar, int Dim, typename OtherDerived>
124
inline static Matrix<Scalar,Dim,Dim> ei_toRotationMatrix(const RotationBase<OtherDerived,Dim>& r)
126
return r.toRotationMatrix();
129
template<typename Scalar, int Dim, typename OtherDerived>
130
inline static const MatrixBase<OtherDerived>& ei_toRotationMatrix(const MatrixBase<OtherDerived>& mat)
132
EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
133
YOU_MADE_A_PROGRAMMING_MISTAKE)
137
#endif // EIGEN_ROTATIONBASE_H