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. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
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 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:19