| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Rot2.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Dec 9, 2009 | 
					
						
							|  |  |  |  *      Author: Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Rot2.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-10 07:15:06 +08:00
										 |  |  | #include "Lie-inl.h"
 | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-10 07:15:06 +08:00
										 |  |  |   /** Explicit instantiation of base class to export members */ | 
					
						
							|  |  |  |   template class Lie<Rot2>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-15 08:00:02 +08:00
										 |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   void Rot2::print(const string& s) const { | 
					
						
							| 
									
										
										
										
											2009-12-18 08:09:54 +08:00
										 |  |  |     cout << s << ":" << theta() << endl; | 
					
						
							| 
									
										
										
										
											2009-12-15 08:00:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   bool Rot2::equals(const Rot2& R, double tol) const { | 
					
						
							|  |  |  |     return fabs(c_ - R.c_) <= tol && fabs(s_ - R.s_) <= tol; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Rot2::matrix() const { | 
					
						
							|  |  |  |     return Matrix_(2, 2, c_, -s_, s_, c_); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Rot2::transpose() const { | 
					
						
							|  |  |  |     return Matrix_(2, 2, c_, s_, -s_, c_); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Rot2::negtranspose() const { | 
					
						
							|  |  |  |     return Matrix_(2, 2, -c_, -s_, s_, -c_); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Point2 Rot2::unrotate(const Point2& p) const { | 
					
						
							|  |  |  |     return Point2( | 
					
						
							|  |  |  |         c_ * p.x() + s_ * p.y(), | 
					
						
							|  |  |  |         -s_ * p.x() + c_ * p.y() | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Point2 rotate(const Rot2& R, const Point2& p) { | 
					
						
							| 
									
										
										
										
											2010-01-08 08:40:17 +08:00
										 |  |  |     return Point2( | 
					
						
							|  |  |  |         R.c() * p.x() - R.s() * p.y(), | 
					
						
							|  |  |  |         R.s() * p.x() + R.c() * p.y()); | 
					
						
							| 
									
										
										
										
											2009-12-15 08:00:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   // see libraries/caml/geometry/math.ml
 | 
					
						
							|  |  |  |   Matrix Drotate1(const Rot2& R, const Point2& p) { | 
					
						
							|  |  |  |     Point2 q = R*p; | 
					
						
							|  |  |  |     return Matrix_(2, 1, -q.y(), q.x()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Drotate2(const Rot2& R) { | 
					
						
							|  |  |  |     return R.matrix(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Point2 unrotate(const Rot2& R, const Point2& p) { | 
					
						
							|  |  |  |     return R.unrotate(p); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   /** see libraries/caml/geometry/math.lyx, derivative of unrotate              */ | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Dunrotate1(const Rot2 & R, const Point2 & p) { | 
					
						
							|  |  |  |     Point2 q = R.unrotate(p); | 
					
						
							|  |  |  |     return Matrix_(2, 1, q.y(), -q.x()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   Matrix Dunrotate2(const Rot2 & R) { | 
					
						
							|  |  |  |     return R.transpose(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // gtsam
 |