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
00045 namespace internal {
00046
00047 template<typename _Scalar> struct traits<Rotation2D<_Scalar> >
00048 {
00049 typedef _Scalar Scalar;
00050 };
00051 }
00052
00053 template<typename _Scalar>
00054 class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
00055 {
00056 typedef RotationBase<Rotation2D<_Scalar>,2> Base;
00057
00058 public:
00059
00060 using Base::operator*;
00061
00062 enum { Dim = 2 };
00064 typedef _Scalar Scalar;
00065 typedef Matrix<Scalar,2,1> Vector2;
00066 typedef Matrix<Scalar,2,2> Matrix2;
00067
00068 protected:
00069
00070 Scalar m_angle;
00071
00072 public:
00073
00075 inline Rotation2D(Scalar a) : m_angle(a) {}
00076
00078 inline Scalar angle() const { return m_angle; }
00079
00081 inline Scalar& angle() { return m_angle; }
00082
00084 inline Rotation2D inverse() const { return -m_angle; }
00085
00087 inline Rotation2D operator*(const Rotation2D& other) const
00088 { return m_angle + other.m_angle; }
00089
00091 inline Rotation2D& operator*=(const Rotation2D& other)
00092 { return m_angle += other.m_angle; return *this; }
00093
00095 Vector2 operator* (const Vector2& vec) const
00096 { return toRotationMatrix() * vec; }
00097
00098 template<typename Derived>
00099 Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
00100 Matrix2 toRotationMatrix(void) const;
00101
00105 inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
00106 { return m_angle * (1-t) + other.angle() * t; }
00107
00113 template<typename NewScalarType>
00114 inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
00115 { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
00116
00118 template<typename OtherScalarType>
00119 inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
00120 {
00121 m_angle = Scalar(other.angle());
00122 }
00123
00124 inline static Rotation2D Identity() { return Rotation2D(0); }
00125
00130 bool isApprox(const Rotation2D& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00131 { return internal::isApprox(m_angle,other.m_angle, prec); }
00132 };
00133
00136 typedef Rotation2D<float> Rotation2Df;
00139 typedef Rotation2D<double> Rotation2Dd;
00140
00145 template<typename Scalar>
00146 template<typename Derived>
00147 Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
00148 {
00149 EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
00150 m_angle = internal::atan2(mat.coeff(1,0), mat.coeff(0,0));
00151 return *this;
00152 }
00153
00156 template<typename Scalar>
00157 typename Rotation2D<Scalar>::Matrix2
00158 Rotation2D<Scalar>::toRotationMatrix(void) const
00159 {
00160 Scalar sinA = internal::sin(m_angle);
00161 Scalar cosA = internal::cos(m_angle);
00162 return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
00163 }
00164
00165 #endif // EIGEN_ROTATION2D_H