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 <gael.guennebaud@inria.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 #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 } // end namespace internal
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


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