Rotation2D.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
00011 
00012 namespace Eigen { 
00013 
00030 template<typename _Scalar> struct ei_traits<Rotation2D<_Scalar> >
00031 {
00032   typedef _Scalar Scalar;
00033 };
00034 
00035 template<typename _Scalar>
00036 class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
00037 {
00038   typedef RotationBase<Rotation2D<_Scalar>,2> Base;
00039 
00040 public:
00041 
00042   using Base::operator*;
00043 
00044   enum { Dim = 2 };
00046   typedef _Scalar Scalar;
00047   typedef Matrix<Scalar,2,1> Vector2;
00048   typedef Matrix<Scalar,2,2> Matrix2;
00049 
00050 protected:
00051 
00052   Scalar m_angle;
00053 
00054 public:
00055 
00057   inline Rotation2D(Scalar a) : m_angle(a) {}
00058 
00060   inline Scalar angle() const { return m_angle; }
00061 
00063   inline Scalar& angle() { return m_angle; }
00064 
00066   inline Rotation2D inverse() const { return -m_angle; }
00067 
00069   inline Rotation2D operator*(const Rotation2D& other) const
00070   { return m_angle + other.m_angle; }
00071 
00073   inline Rotation2D& operator*=(const Rotation2D& other)
00074   { return m_angle += other.m_angle; return *this; }
00075 
00077   Vector2 operator* (const Vector2& vec) const
00078   { return toRotationMatrix() * vec; }
00079 
00080   template<typename Derived>
00081   Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
00082   Matrix2 toRotationMatrix(void) const;
00083 
00087   inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
00088   { return m_angle * (1-t) + other.angle() * t; }
00089 
00095   template<typename NewScalarType>
00096   inline typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
00097   { return typename internal::cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
00098 
00100   template<typename OtherScalarType>
00101   inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
00102   {
00103     m_angle = Scalar(other.angle());
00104   }
00105 
00110   bool isApprox(const Rotation2D& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00111   { return ei_isApprox(m_angle,other.m_angle, prec); }
00112 };
00113 
00116 typedef Rotation2D<float> Rotation2Df;
00119 typedef Rotation2D<double> Rotation2Dd;
00120 
00125 template<typename Scalar>
00126 template<typename Derived>
00127 Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
00128 {
00129   EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
00130   m_angle = ei_atan2(mat.coeff(1,0), mat.coeff(0,0));
00131   return *this;
00132 }
00133 
00136 template<typename Scalar>
00137 typename Rotation2D<Scalar>::Matrix2
00138 Rotation2D<Scalar>::toRotationMatrix(void) const
00139 {
00140   Scalar sinA = ei_sin(m_angle);
00141   Scalar cosA = ei_cos(m_angle);
00142   return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
00143 }
00144 
00145 } // end namespace Eigen


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:59:33