Rotation2D.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 // 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.
10 //
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.
15 //
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.
20 //
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/>.
24 
25 #ifndef EIGEN_ROTATION2D_H
26 #define EIGEN_ROTATION2D_H
27 
28 namespace Eigen {
29 
47 namespace internal {
48 
49 template<typename _Scalar> struct traits<Rotation2D<_Scalar> >
50 {
51  typedef _Scalar Scalar;
52 };
53 } // end namespace internal
54 
55 template<typename _Scalar>
56 class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
57 {
59 
60 public:
61 
62  using Base::operator*;
63 
64  enum { Dim = 2 };
66  typedef _Scalar Scalar;
69 
70 protected:
71 
73 
74 public:
75 
77  inline Rotation2D(Scalar a) : m_angle(a) {}
78 
80  inline Scalar angle() const { return m_angle; }
81 
83  inline Scalar& angle() { return m_angle; }
84 
86  inline Rotation2D inverse() const { return -m_angle; }
87 
89  inline Rotation2D operator*(const Rotation2D& other) const
90  { return m_angle + other.m_angle; }
91 
93  inline Rotation2D& operator*=(const Rotation2D& other)
94  { m_angle += other.m_angle; return *this; }
95 
97  Vector2 operator* (const Vector2& vec) const
98  { return toRotationMatrix() * vec; }
99 
100  template<typename Derived>
102  Matrix2 toRotationMatrix(void) const;
103 
107  inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
108  { return m_angle * (1-t) + other.angle() * t; }
109 
115  template<typename NewScalarType>
116  inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
117  { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
118 
120  template<typename OtherScalarType>
121  inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
122  {
123  m_angle = Scalar(other.angle());
124  }
125 
126  static inline Rotation2D Identity() { return Rotation2D(0); }
127 
133  { return internal::isApprox(m_angle,other.m_angle, prec); }
134 };
135 
142 
147 template<typename Scalar>
148 template<typename Derived>
150 {
151  EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
152  m_angle = internal::atan2(mat.coeff(1,0), mat.coeff(0,0));
153  return *this;
154 }
155 
158 template<typename Scalar>
161 {
162  Scalar sinA = internal::sin(m_angle);
163  Scalar cosA = internal::cos(m_angle);
164  return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
165 }
166 
167 } // end namespace Eigen
168 
169 #endif // EIGEN_ROTATION2D_H