Share Pastebin
Guest
Public paste!

Robot pose (new)

By: a guest | Sep 5th, 2010 | Syntax: C++ | Size: 1.27 KB | Hits: 24 | Expires: Never
Copy text to clipboard
  1. #include <complex>
  2.  
  3. class pose {
  4.  
  5.   using std::complex;
  6.  
  7.   complex<double> translation;
  8.   complex<double> rotation;
  9.  
  10.   pose (const complex<double>& t, const complex<double>& r)
  11.     : translation(t), rotation(r) { }
  12.  
  13. public:
  14.  
  15.   pose () : translation(), rotation(1) { }
  16.  
  17.   pose (double x = 0, double y = 0, double bearing = 0)
  18.     : translation(x,y), rotation(std::polar(1.0, bearing)) { }
  19.  
  20.   double x () const       { return translation.real(); }
  21.   double y () const       { return translation.imag(); }
  22.   double bearing () const { return std::arg(rotation); }
  23.   double distance () const { return std::abs(translation); }
  24.   double direction () const { return std::arg(translation); }
  25.  
  26.   pose& operator+= (const pose& p) {
  27.     translation += rotation * p.translation;
  28.     rotation *= p.rotation;
  29.     return *this;
  30.   }
  31.  
  32.   pose operator- () const {
  33.     complex<double> inverse_rot = conj(rotation);
  34.     return pose (-translation*inverse_rot, inverse_rot);
  35.   }
  36.  
  37.   pose& operator-= (const pose& p) {
  38.     return *this += -p;
  39.   }
  40.  
  41.   friend class observation;
  42.   friend observation operator+ (const pose&, const observation&);
  43.  
  44. };
  45.  
  46. inline pose operator+ (pose a, const pose& b) { return a += b; }
  47.  
  48. inline pose operator- (pose a, const pose& b) { return a -= b; }