rtcRotation2D.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: Autonomous Technologies
00011  * file .......: rtcRotation2D.h
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 02/29/2008
00015  * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $
00016  * changed by .: $Author: benjaminpitzer $
00017  * revision ...: $Revision: 14 $
00018  */
00019 #ifndef RTC_ROTATION2D_H
00020 #define RTC_ROTATION2D_H
00021 
00022 //== INCLUDES ==================================================================
00023 #include "rtc/rtcMath.h"
00024 #include "rtc/rtcTransform2D.h"
00025 #include "rtc/rtcSMat2.h"
00026 
00027 //== NAMESPACES ================================================================
00028 namespace rtc {
00029 
00030 //== FORWARD DECLARATIONS ======================================================
00031 template <class T> class Rotation2D;    // Rotation2D matrix (3x3)
00032 template <class T> class Transform2D;   // Rigid tranform matrix (4x4)
00033 
00043 template <class T>
00044 class Rotation2D: public SMat2<T> {
00045 public:
00047   using SMat2<T>::x;
00048   using SMat2<T>::set;
00049 
00051   Rotation2D();
00052   Rotation2D(const T x11, const T x12,
00053              const T x21, const T x22);
00054   Rotation2D(const Mat<T,2,2>& m);
00055   Rotation2D(const T& theta);
00056 
00058   void set(const T& theta);
00059 
00061   void apply(Vec2<T>& v) const;
00062   Vec2<T> apply(const Vec2<T>& v) const;
00063 
00065   T getTheta();
00066 };
00067 
00068 // Declare a few common typdefs
00069 typedef Rotation2D<float> Rotation2Df;
00070 typedef Rotation2D<double> Rotation2Dd;
00071 
00072 //==============================================================================
00073 // Rotation2D<T>
00074 //==============================================================================
00075 
00076 // Constructors
00077 
00080 template <class T>
00081 inline Rotation2D<T>::Rotation2D() {
00082   x[0] = x[3] = T(1);
00083   x[1] = x[2] = 0;
00084 }
00085 
00088 template <class T>
00089 inline Rotation2D<T>::Rotation2D(const T x11, const T x12,
00090                                  const T x21, const T x22) {
00091   x[0] = x11; x[1] = x12;
00092   x[2] = x21; x[3] = x22;
00093 }
00094 
00097 template <class T>
00098 inline Rotation2D<T>::Rotation2D(const Mat<T,2,2>& m) : SMat2<T>(m) {}
00099 
00102 template <class T>
00103 inline Rotation2D<T>::Rotation2D(const T& theta) {
00104   x[0] = cos(theta);
00105   x[1] = -sin(theta);
00106   x[2] = sin(theta);
00107   x[3] = cos(theta);
00108 }
00109 
00110 // Mutators
00111 
00114 template <class T>
00115 inline void Rotation2D<T>::set(const T& theta) {
00116   x[0] = cos(theta);
00117   x[1] = -sin(theta);
00118   x[2] = sin(theta);
00119   x[3] = cos(theta);
00120 }
00121 
00122 // Accessors
00123 template <class T>
00124 inline T Rotation2D<T>::getTheta() {
00125   return atan2(x[2],x[0]);
00126 }
00127 
00130 template <class T>
00131 inline void Rotation2D<T>::apply(Vec2<T>& v) const {
00132   v.set((*this)*v);
00133 }
00134 
00137 template <class T>
00138 inline Vec2<T> Rotation2D<T>::apply(const Vec2<T>& v) const {
00139   return((*this)*v);
00140 }
00141 
00142 //==============================================================================
00143 } // namespace rtc
00144 //==============================================================================
00145 #endif // RTC_ROTATION2D_H defined
00146 //==============================================================================


rtc
Author(s): Benjamin Pitzer
autogenerated on Thu Jan 2 2014 11:04:53