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
00026
00027
00044 template<typename _Scalar> struct ei_traits<Rotation2D<_Scalar> >
00045 {
00046 typedef _Scalar Scalar;
00047 };
00048
00049 template<typename _Scalar>
00050 class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
00051 {
00052 typedef RotationBase<Rotation2D<_Scalar>,2> Base;
00053
00054 public:
00055
00056 using Base::operator*;
00057
00058 enum { Dim = 2 };
00060 typedef _Scalar Scalar;
00061 typedef Matrix<Scalar,2,1> Vector2;
00062 typedef Matrix<Scalar,2,2> Matrix2;
00063
00064 protected:
00065
00066 Scalar m_angle;
00067
00068 public:
00069
00071 inline Rotation2D(Scalar a) : m_angle(a) {}
00072
00074 inline Scalar angle() const { return m_angle; }
00075
00077 inline Scalar& angle() { return m_angle; }
00078
00080 inline Rotation2D inverse() const { return -m_angle; }
00081
00083 inline Rotation2D operator*(const Rotation2D& other) const
00084 { return m_angle + other.m_angle; }
00085
00087 inline Rotation2D& operator*=(const Rotation2D& other)
00088 { return m_angle += other.m_angle; return *this; }
00089
00091 Vector2 operator* (const Vector2& vec) const
00092 { return toRotationMatrix() * vec; }
00093
00094 template<typename Derived>
00095 Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
00096 Matrix2 toRotationMatrix(void) const;
00097
00101 inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
00102 { return m_angle * (1-t) + other.angle() * t; }
00103
00109 template<typename NewScalarType>
00110 inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
00111 { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
00112
00114 template<typename OtherScalarType>
00115 inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
00116 {
00117 m_angle = Scalar(other.angle());
00118 }
00119
00124 bool isApprox(const Rotation2D& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00125 { return ei_isApprox(m_angle,other.m_angle, prec); }
00126 };
00127
00130 typedef Rotation2D<float> Rotation2Df;
00133 typedef Rotation2D<double> Rotation2Dd;
00134
00139 template<typename Scalar>
00140 template<typename Derived>
00141 Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
00142 {
00143 EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
00144 m_angle = ei_atan2(mat.coeff(1,0), mat.coeff(0,0));
00145 return *this;
00146 }
00147
00150 template<typename Scalar>
00151 typename Rotation2D<Scalar>::Matrix2
00152 Rotation2D<Scalar>::toRotationMatrix(void) const
00153 {
00154 Scalar sinA = ei_sin(m_angle);
00155 Scalar cosA = ei_cos(m_angle);
00156 return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
00157 }