Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_ROTATION2D_H
00026 #define EIGEN_ROTATION2D_H
00027
00028 namespace Eigen {
00029
00047 namespace internal {
00048
00049 template<typename _Scalar> struct traits<Rotation2D<_Scalar> >
00050 {
00051 typedef _Scalar Scalar;
00052 };
00053 }
00054
00055 template<typename _Scalar>
00056 class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
00057 {
00058 typedef RotationBase<Rotation2D<_Scalar>,2> Base;
00059
00060 public:
00061
00062 using Base::operator*;
00063
00064 enum { Dim = 2 };
00066 typedef _Scalar Scalar;
00067 typedef Matrix<Scalar,2,1> Vector2;
00068 typedef Matrix<Scalar,2,2> Matrix2;
00069
00070 protected:
00071
00072 Scalar m_angle;
00073
00074 public:
00075
00077 inline Rotation2D(Scalar a) : m_angle(a) {}
00078
00080 inline Scalar angle() const { return m_angle; }
00081
00083 inline Scalar& angle() { return m_angle; }
00084
00086 inline Rotation2D inverse() const { return -m_angle; }
00087
00089 inline Rotation2D operator*(const Rotation2D& other) const
00090 { return m_angle + other.m_angle; }
00091
00093 inline Rotation2D& operator*=(const Rotation2D& other)
00094 { m_angle += other.m_angle; return *this; }
00095
00097 Vector2 operator* (const Vector2& vec) const
00098 { return toRotationMatrix() * vec; }
00099
00100 template<typename Derived>
00101 Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
00102 Matrix2 toRotationMatrix(void) const;
00103
00107 inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
00108 { return m_angle * (1-t) + other.angle() * t; }
00109
00115 template<typename NewScalarType>
00116 inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
00117 { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
00118
00120 template<typename OtherScalarType>
00121 inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
00122 {
00123 m_angle = Scalar(other.angle());
00124 }
00125
00126 static inline Rotation2D Identity() { return Rotation2D(0); }
00127
00132 bool isApprox(const Rotation2D& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00133 { return internal::isApprox(m_angle,other.m_angle, prec); }
00134 };
00135
00138 typedef Rotation2D<float> Rotation2Df;
00141 typedef Rotation2D<double> Rotation2Dd;
00142
00147 template<typename Scalar>
00148 template<typename Derived>
00149 Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
00150 {
00151 EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
00152 m_angle = internal::atan2(mat.coeff(1,0), mat.coeff(0,0));
00153 return *this;
00154 }
00155
00158 template<typename Scalar>
00159 typename Rotation2D<Scalar>::Matrix2
00160 Rotation2D<Scalar>::toRotationMatrix(void) const
00161 {
00162 Scalar sinA = internal::sin(m_angle);
00163 Scalar cosA = internal::cos(m_angle);
00164 return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
00165 }
00166
00167 }
00168
00169 #endif // EIGEN_ROTATION2D_H