GCOP  1.0
group.h
Go to the documentation of this file.
00001 #ifndef GCOP_GROUP_H
00002 #define GCOP_GROUP_H
00003 
00004 #include <Eigen/Dense>
00005 #include "manifold.h"
00006 
00007 namespace gcop {
00008   
00009   using namespace Eigen;
00010 
00031   template <int n, int m>class Group : Manifold<Matrix<double, m, m>, n > {
00032     
00033     typedef Matrix<double, n, 1> Vectornd;
00034     typedef Matrix<double, m, m> Matrixmd;
00035     typedef Matrix<double, n, n> Matrixnd;
00036     
00037   public:
00043     virtual void inv(Matrixmd &gi, const Matrixmd &g) const;
00044 
00050     virtual Matrixmd inv(const Matrixmd &g) const;
00051 
00052 
00059     virtual void diff(Matrixmd &dg, const Matrixmd &ga, const Matrixmd &gb) const;
00060 
00061 
00068     virtual Matrixmd diff(const Matrixmd &ga, const Matrixmd &gb) const;
00069 
00070 
00077     virtual void hat(Matrixmd &g, const Vectornd &v) const = 0;
00078 
00079 
00086     virtual Matrixmd hat(const Vectornd &v) const;
00087 
00088 
00094     virtual void hatinv(Vectornd &v, const Matrixmd &g) const = 0;
00095 
00096 
00102     virtual Vectornd hatinv(const Matrixmd &g) const;
00103 
00104 
00110     virtual void Tg(Matrixnd &M, const Matrixmd &g) const = 0;
00111     
00112 
00118     virtual Matrixnd Tg(const Matrixmd &g) const;
00119 
00126     virtual void Ad(Matrixnd &M, const Matrixmd &g) const = 0;
00127 
00134     virtual Matrixnd Ad(const Matrixmd &g) const;
00135     
00136 
00144     virtual void ad(Matrixnd &M, const Vectornd &v) const = 0;
00145 
00146 
00154     virtual Matrixnd ad(const Vectornd &v) const;
00155     
00156 
00162     virtual void adinv(Vectornd &v, const Matrixnd &M) const = 0;
00163 
00164 
00170     virtual Vectornd adinv(const Matrixnd &M) const;
00171 
00172 
00179     virtual void exp(Matrixmd &g, const Vectornd &v) const = 0;
00180 
00181 
00188     virtual Matrixmd exp(const Vectornd &v) const;
00189 
00190 
00197     virtual void log(Vectornd &v, const Matrixmd &g) const = 0;
00198 
00199 
00206     virtual Vectornd log(const Matrixmd &g) const;
00207 
00208 
00215     virtual void cay(Matrixmd &g, const Vectornd &v) const;
00216 
00217 
00224     virtual Matrixmd cay(const Vectornd &v) const;
00225  
00226 
00233     virtual void cayinv(Vectornd &v, const Matrixmd &g) const;
00234 
00241     virtual Vectornd cayinv(const Matrixmd &g) const;
00242 
00243 
00249     virtual void dcay(Matrixnd &M, const Vectornd &v) const = 0;
00250 
00251 
00257     virtual Matrixnd dcay(const Vectornd &v) const;
00258 
00259 
00265     virtual void dcayinv(Matrixnd &M, const Vectornd &v) const = 0;
00266 
00267 
00273     virtual Matrixnd dcayinv(const Vectornd &v) const;
00274 
00275 
00276     virtual void Lift(Vectornd &v,
00277                       const Matrixmd &ga,
00278                       const Matrixmd &gb);
00279     
00280     
00281     virtual void Retract(Matrixmd &gb,
00282                          const Matrixmd &ga,
00283                          const Vectornd &v);
00284 
00285 
00286     virtual void dtau(Matrixnd &M, const Vectornd &v);
00287 
00288     virtual void Adtau(Matrixnd &M, const Vectornd &v);
00289 
00290 
00291     static const Matrixmd Id;
00292     static const Vectornd e;    
00293   };
00294 
00295 
00296   template <int n, int m> 
00297     Matrix<double, m, m> const Group<n, m>::Id = Matrix<double, m, m>::Identity();
00298   
00299   template <int n, int m> 
00300     Matrix<double, n, 1> const Group<n, m>::e = Matrix<double, n, 1>::Zero();
00301   
00302   
00303   template <int n, int m> 
00304     void Group<n, m>::inv(Matrix<double, m, m> &gi, const Matrix<double, m, m> &g) const
00305     {
00306       // default uses regular matrix inverse
00307       // methods typically override this
00308       gi = g.inverse();
00309     }
00310 
00311   template <int n, int m> 
00312     Matrix<double, m, m> Group<n, m>::inv(const Matrix<double, m, m> &g) const
00313     {
00314       // default uses regular matrix inverse
00315       // methods typically override this
00316       Matrix<double, m, m> gi;
00317       inv(gi, g);
00318       return gi;
00319     }
00320   
00321   
00322   template <int n, int m> 
00323     void Group<n, m>::diff(Matrix<double, m, m> &dg, const Matrix<double, m, m> &ga, const Matrix<double, m, m> &gb) const
00324     {
00325       Matrix<double, m, m> gai;
00326       inv(gai, ga);
00327       dg = gai*gb;
00328     }
00329 
00330   template <int n, int m> 
00331     Matrix<double, m, m> Group<n, m>::diff(const Matrix<double, m, m> &ga, const Matrix<double, m, m> &gb) const
00332     {
00333       Matrix<double, m, m> dg;
00334       diff(dg, ga, gb);
00335       return dg;
00336     }
00337   
00338   template <int n, int m> 
00339     Matrix<double, m, m> Group<n, m>::hat(const Vectornd &v) const
00340     {
00341       Matrix<double, m, m> g;
00342       hat(g, v);
00343       return g;
00344     }
00345 
00346   template <int n, int m> 
00347     Matrix<double, n, 1> Group<n, m>::hatinv(const Matrixmd &g) const
00348     {
00349       Matrix<double, n, 1> v;
00350       hatinv(v, g);
00351       return v;
00352     }
00353 
00354 
00355   template <int n, int m> 
00356     Matrix<double, n, n> Group<n, m>::Tg(const Matrixmd &g) const
00357     {
00358       Matrixnd M;
00359       Tg(M, g);
00360       return M;
00361     }
00362   
00363 
00364   /*  
00365   template <int n, int m> 
00366     void Group<T, n>::exp(Matrix<double, m, m> &g, const MatrixNd &v) const
00367     {
00368       // by default only provide a first-order approximation
00369       // this function is typically overriden
00370       g = Id + hat(v);
00371     }
00372   */
00373 
00374   template <int n, int m> 
00375     Matrix<double, m, m> Group<n, m>::exp(const Matrix<double, n, 1> &v) const
00376     {
00377       Matrix<double, m, m> g;
00378       exp(g, v);
00379       return g;
00380     }
00381 
00382 
00383   /*
00384   template <int n, int m> 
00385     void Group<T, n>::log(MatrixNd &v, const Matrix<double, m, m> &g) const
00386     {
00387       // by default only provide a first-order approximation
00388       // this function is typically overriden
00389       v = hatinv(g - Id);
00390     }
00391   */
00392 
00393   template <int n, int m> 
00394     Matrix<double, n, 1> Group<n, m>::log(const Matrix<double, m, m> &g) const
00395     {
00396       Matrix<double, n, 1> v;
00397       log(v, g);
00398       return v;
00399     }
00400 
00401   
00402   template <int n, int m> 
00403     void Group<n, m>::cay(Matrix<double, m, m> &g, const Matrix<double, n, 1> &v) const
00404     {
00405       Matrix<double, m, m> vhh;
00406       hat(vhh, v/2);
00407       g = (Id - vhh).inverse()*(Id + vhh);
00408     }
00409 
00410 
00411   template <int n, int m> 
00412     Matrix<double, m, m> Group<n, m>::cay(const Matrix<double, n, 1> &v) const
00413     {
00414       Matrix<double, m, m> vhh;
00415       hat(vhh, v/2);
00416       return (Id - vhh).inverse()*(Id + vhh);
00417     }
00418 
00419   
00420   template <int n, int m> 
00421     void Group<n, m>::cayinv(Matrix<double, n, 1> &v, const Matrix<double, m, m> &g) const
00422     {
00423       hatinv(v, (Id + g).inverse()*(Id - g));
00424       v = -2*v;
00425     }
00426 
00427   template <int n, int m> 
00428     Matrix<double, n, 1> Group<n, m>::cayinv(const Matrix<double, m, m> &g) const
00429     {
00430       return -2*hatinv((Id + g).inverse()*(Id - g));
00431     }
00432 
00433 
00434   template <int n, int m> 
00435     Matrix<double, n, n> Group<n, m>::ad(const Matrix<double, n, 1> &v) const
00436     {
00437       Matrix<double, n, n> M;
00438       ad(M, v);
00439       return M;
00440     }
00441 
00442 
00443   template <int n, int m> 
00444     Matrix<double, n, 1> Group<n, m>::adinv(const Matrix<double, n, n> &M) const
00445     {
00446       Matrix<double, n, 1> v;
00447       adinv(v, M);
00448       return v;
00449     }
00450 
00451 
00452   template <int n, int m> 
00453     Matrix<double, n, n> Group<n, m>::Ad(const Matrix<double, m, m> &g) const
00454     {
00455       Matrix<double, n, n> M;
00456       Ad(M, g);
00457       return M;
00458     }
00459 
00460 
00461   template <int n, int m> 
00462     Matrix<double, n, n> Group<n, m>::dcay(const Matrix<double, n, 1> &v) const
00463     {
00464       Matrix<double, n, n> M;
00465       dcay(M, v);
00466       return M;
00467     }
00468 
00469   template <int n, int m> 
00470     Matrix<double, n, n> Group<n, m>::dcayinv(const Matrix<double, n, 1> &v) const
00471     {
00472       Matrix<double, n, n> M;
00473       dcayinv(M, v);
00474       return M;
00475     }
00476 
00477   template <int n, int m> 
00478     void Group<n, m>::Lift(Matrix<double, n, 1> &v,
00479                            const Matrix<double, m, m> &ga,                           
00480                            const Matrix<double, m, m> &gb) {
00481     
00482     Matrix<double, m, m> gai;
00483     inv(gai, ga);
00484     log(v, gai*gb);
00485   }
00486 
00487 
00488   template <int n, int m> 
00489     void Group<n, m>::Retract(Matrix<double, m, m> &gb,
00490                               const Matrix<double, m, m> &ga,
00491                               const Matrix<double, n, 1> &v) {
00492     
00493     Matrix<double, m, m> g;
00494     cay(g, v);
00495     gb = ga*g;
00496   }
00497 
00498   template <int n, int m> 
00499     void Group<n, m>::dtau(Matrixnd &M, const Vectornd &v) {
00500     dcay(M, v);
00501   }
00502   
00503   template <int n, int m> 
00504     void Group<n, m>::Adtau(Matrixnd &M, const Vectornd &v) {
00505     Matrix<double, m, m> g;
00506     cay(g, v);
00507     Ad(M, g);
00508   }
00509 
00510 
00511 
00512 }
00513 
00514 #endif
00515 
00516