Eigen  3.2.10
 
Loading...
Searching...
No Matches
Rotation2D.h
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
13namespace Eigen {
14
31
32namespace internal {
33
34template<typename _Scalar> struct traits<Rotation2D<_Scalar> >
35{
36 typedef _Scalar Scalar;
37};
38} // end namespace internal
39
40template<typename _Scalar>
41class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
42{
44
45public:
46
47 using Base::operator*;
48
49 enum { Dim = 2 };
51 typedef _Scalar Scalar;
52 typedef Matrix<Scalar,2,1> Vector2;
53 typedef Matrix<Scalar,2,2> Matrix2;
54
55protected:
56
57 Scalar m_angle;
58
59public:
60
62 inline Rotation2D(const Scalar& a) : m_angle(a) {}
63
66
68 inline Scalar angle() const { return m_angle; }
69
71 inline Scalar& angle() { return m_angle; }
72
74 inline Rotation2D inverse() const { return -m_angle; }
75
77 inline Rotation2D operator*(const Rotation2D& other) const
78 { return m_angle + other.m_angle; }
79
81 inline Rotation2D& operator*=(const Rotation2D& other)
82 { m_angle += other.m_angle; return *this; }
83
85 Vector2 operator* (const Vector2& vec) const
86 { return toRotationMatrix() * vec; }
87
88 template<typename Derived>
89 Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
90 Matrix2 toRotationMatrix() const;
91
95 inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const
96 { return m_angle * (1-t) + other.angle() * t; }
97
103 template<typename NewScalarType>
104 inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
105 { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
106
108 template<typename OtherScalarType>
109 inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
110 {
111 m_angle = Scalar(other.angle());
112 }
113
114 static inline Rotation2D Identity() { return Rotation2D(0); }
115
120 bool isApprox(const Rotation2D& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
121 { return internal::isApprox(m_angle,other.m_angle, prec); }
122};
123
130
135template<typename Scalar>
136template<typename Derived>
137Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
138{
139 using std::atan2;
140 EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
141 m_angle = atan2(mat.coeff(1,0), mat.coeff(0,0));
142 return *this;
143}
144
147template<typename Scalar>
148typename Rotation2D<Scalar>::Matrix2
150{
151 using std::sin;
152 using std::cos;
153 Scalar sinA = sin(m_angle);
154 Scalar cosA = cos(m_angle);
155 return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
156}
157
158} // end namespace Eigen
159
160#endif // EIGEN_ROTATION2D_H
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129
Represents a rotation/orientation in a 2 dimensional space.
Definition Rotation2D.h:42
Rotation2D operator*(const Rotation2D &other) const
Definition Rotation2D.h:77
Rotation2D inverse() const
Definition Rotation2D.h:74
Rotation2D(const Rotation2D< OtherScalarType > &other)
Definition Rotation2D.h:109
Rotation2D(const Scalar &a)
Definition Rotation2D.h:62
bool isApprox(const Rotation2D &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Rotation2D.h:120
Rotation2D slerp(const Scalar &t, const Rotation2D &other) const
Definition Rotation2D.h:95
Matrix2 toRotationMatrix() const
Definition Rotation2D.h:149
Scalar angle() const
Definition Rotation2D.h:68
Scalar & angle()
Definition Rotation2D.h:71
internal::cast_return_type< Rotation2D, Rotation2D< NewScalarType > >::type cast() const
Definition Rotation2D.h:104
Rotation2D()
Definition Rotation2D.h:65
_Scalar Scalar
Definition Rotation2D.h:51
Rotation2D & operator*=(const Rotation2D &other)
Definition Rotation2D.h:81
Common base class for compact rotation representations.
Definition RotationBase.h:30
Rotation2D< double > Rotation2Dd
Definition Rotation2D.h:129
Rotation2D< float > Rotation2Df
Definition Rotation2D.h:126
Definition LDLT.h:18