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 // 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_ROTATION2D_H
11 #define EIGEN_ROTATION2D_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
35 namespace internal {
36 
37 template <typename Scalar_>
38 struct traits<Rotation2D<Scalar_> > {
39  typedef Scalar_ Scalar;
40 };
41 } // end namespace internal
42 
43 template <typename Scalar_>
44 class Rotation2D : public RotationBase<Rotation2D<Scalar_>, 2> {
46 
47  public:
48  using Base::operator*;
49 
50  enum { Dim = 2 };
52  typedef Scalar_ Scalar;
55 
56  protected:
58 
59  public:
61  EIGEN_DEVICE_FUNC explicit inline Rotation2D(const Scalar& a) : m_angle(a) {}
62 
65 
70  template <typename Derived>
72  fromRotationMatrix(m.derived());
73  }
74 
76  EIGEN_DEVICE_FUNC inline Scalar angle() const { return m_angle; }
77 
79  EIGEN_DEVICE_FUNC inline Scalar& angle() { return m_angle; }
80 
84  return tmp < Scalar(0) ? tmp + Scalar(2 * EIGEN_PI) : tmp;
85  }
86 
90  if (tmp > Scalar(EIGEN_PI))
91  tmp -= Scalar(2 * EIGEN_PI);
92  else if (tmp < -Scalar(EIGEN_PI))
93  tmp += Scalar(2 * EIGEN_PI);
94  return tmp;
95  }
96 
98  EIGEN_DEVICE_FUNC inline Rotation2D inverse() const { return Rotation2D(-m_angle); }
99 
101  EIGEN_DEVICE_FUNC inline Rotation2D operator*(const Rotation2D& other) const {
102  return Rotation2D(m_angle + other.m_angle);
103  }
104 
107  m_angle += other.m_angle;
108  return *this;
109  }
110 
112  EIGEN_DEVICE_FUNC Vector2 operator*(const Vector2& vec) const { return toRotationMatrix() * vec; }
113 
114  template <typename Derived>
117 
125  template <typename Derived>
127  return fromRotationMatrix(m.derived());
128  }
129 
133  EIGEN_DEVICE_FUNC inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const {
134  Scalar dist = Rotation2D(other.m_angle - m_angle).smallestAngle();
135  return Rotation2D(m_angle + dist * t);
136  }
137 
143  template <typename NewScalarType>
145  const {
147  }
148 
150  template <typename OtherScalarType>
152  m_angle = Scalar(other.angle());
153  }
154 
155  EIGEN_DEVICE_FUNC static inline Rotation2D Identity() { return Rotation2D(0); }
156 
161  EIGEN_DEVICE_FUNC bool isApprox(const Rotation2D& other, const typename NumTraits<Scalar>::Real& prec =
163  return internal::isApprox(m_angle, other.m_angle, prec);
164  }
165 };
166 
173 
178 template <typename Scalar>
179 template <typename Derived>
182  EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime == 2 && Derived::ColsAtCompileTime == 2,
183  YOU_MADE_A_PROGRAMMING_MISTAKE)
184  m_angle = atan2(mat.coeff(1, 0), mat.coeff(0, 0));
185  return *this;
186 }
187 
190 template <typename Scalar>
194  Scalar sinA = sin(m_angle);
195  Scalar cosA = cos(m_angle);
196  return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
197 }
198 
199 } // end namespace Eigen
200 
201 #endif // EIGEN_ROTATION2D_H
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1090
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_PI
Definition: MathFunctions.h:16
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Represents a rotation/orientation in a 2 dimensional space.
Definition: Rotation2D.h:44
Matrix< Scalar, 2, 1 > Vector2
Definition: Rotation2D.h:53
EIGEN_DEVICE_FUNC Rotation2D(const Scalar &a)
Definition: Rotation2D.h:61
EIGEN_DEVICE_FUNC Scalar & angle()
Definition: Rotation2D.h:79
EIGEN_DEVICE_FUNC Rotation2D(const MatrixBase< Derived > &m)
Definition: Rotation2D.h:71
EIGEN_DEVICE_FUNC Matrix2 toRotationMatrix() const
Definition: Rotation2D.h:191
EIGEN_DEVICE_FUNC Rotation2D()
Definition: Rotation2D.h:64
EIGEN_DEVICE_FUNC bool isApprox(const Rotation2D &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Rotation2D.h:161
EIGEN_DEVICE_FUNC Rotation2D(const Rotation2D< OtherScalarType > &other)
Definition: Rotation2D.h:151
EIGEN_DEVICE_FUNC Rotation2D & operator=(const MatrixBase< Derived > &m)
Definition: Rotation2D.h:126
EIGEN_DEVICE_FUNC Scalar angle() const
Definition: Rotation2D.h:76
EIGEN_DEVICE_FUNC Scalar smallestAngle() const
Definition: Rotation2D.h:88
RotationBase< Rotation2D< Scalar_ >, 2 > Base
Definition: Rotation2D.h:45
EIGEN_DEVICE_FUNC Rotation2D slerp(const Scalar &t, const Rotation2D &other) const
Definition: Rotation2D.h:133
@ Dim
Definition: Rotation2D.h:50
EIGEN_DEVICE_FUNC internal::cast_return_type< Rotation2D, Rotation2D< NewScalarType > >::type cast() const
Definition: Rotation2D.h:144
EIGEN_DEVICE_FUNC Rotation2D operator*(const Rotation2D &other) const
Definition: Rotation2D.h:101
EIGEN_DEVICE_FUNC Rotation2D & operator*=(const Rotation2D &other)
Definition: Rotation2D.h:106
EIGEN_DEVICE_FUNC Rotation2D inverse() const
Definition: Rotation2D.h:98
static EIGEN_DEVICE_FUNC Rotation2D Identity()
Definition: Rotation2D.h:155
Matrix< Scalar, 2, 2 > Matrix2
Definition: Rotation2D.h:54
Scalar m_angle
Definition: Rotation2D.h:57
EIGEN_DEVICE_FUNC Scalar smallestPositiveAngle() const
Definition: Rotation2D.h:82
EIGEN_DEVICE_FUNC Rotation2D & fromRotationMatrix(const MatrixBase< Derived > &m)
Scalar_ Scalar
Definition: Rotation2D.h:52
EIGEN_DEVICE_FUNC Vector2 operator*(const Vector2 &vec) const
Definition: Rotation2D.h:112
Common base class for compact rotation representations.
Definition: RotationBase.h:32
Scalar coeff(Index row, Index col) const
Definition: SparseMatrix.h:211
Rotation2D< float > Rotation2Df
Definition: Rotation2D.h:169
Rotation2D< double > Rotation2Dd
Definition: Rotation2D.h:172
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T fmod(const T &a, const T &b)
Definition: MathFunctions.h:1788
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
AutoDiffScalar< Matrix< typename internal::traits< internal::remove_all_t< DerTypeA > >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
Definition: AutoDiffScalar.h:558
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
t
Definition: plotPSD.py:36
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: XprHelper.h:583
Scalar_ Scalar
Definition: Rotation2D.h:39
Definition: ForwardDeclarations.h:21