ISeeML  1.0
OrPtConfig.hpp
1 //
2 // Definition of iSeeML::rob::OrPtConfig, class of ISeeML standard
3 // robotic configurations.
4 //
5 
6 // To only include this definition once
7 #ifndef ISEEML_ROB_ORIENT_POINT_HH
8 #define ISEEML_ROB_ORIENT_POINT_HH
9 
10 
11 // This class needs the definition of iSeeML::rob::Object.
12 #include <iSeeML/rob/Object.hpp>
13 // This class needs the definition of iSeeML::geom::Point.
14 #include <iSeeML/geom/Point.hpp>
15 
16 
46  // === Object's Fields ==========================================
47 
48  iSeeML::geom::Point Position;
49  double Orientation;
50 
51 public:
56  static const string ClassName;
57 
58 
59  // === Constructors and Destructors =============================
60 
67  OrPtConfig() : Position(), Orientation(0) {}
68 
78  OrPtConfig(const iSeeML::geom::Point& P, const double& theta) :
79  Position(P), Orientation( mod2pi(theta) ) {}
80 
92  OrPtConfig(const double& x, const double& y,
93  const double& theta) :
94  Position(x, y), Orientation( mod2pi(theta) ) {}
95 
96  // The default copy constructor is OK.
97 
98 
100  virtual ~OrPtConfig() {}
101 
102 
103  // === Description Methods ======================================
104 
114  { return *( (iSeeML::Object*) (new OrPtConfig(*this)) ); }
115 
124  void writeTo(ostream& O) const { algWriteTo(O); }
125 
126 
132  const iSeeML::geom::Point& position() const { return Position; }
133 
139  const double& orientation() const { return Orientation; }
140 
152  { return ( P - position() ).rotate( -orientation() ); }
153 
169  { return OrPtConfig( iSeeML::geom::Point()
170  + projection( q.position() ),
171  q.orientation() - orientation() ); }
172 
173 protected:
182  int algDimension() const { return 3; }
183 
200  double algCoord(const int i) const {
201  switch (i) { case 1: return position().xCoord();
202  case 2: return position().yCoord();
203  case 3: return orientation(); default:
204 #ifdef ISEEML_CHECK_ORPT_CONFIG_PRECOND
205  cerr << ClassName << "::coord: parameter " << i << endl
206  << " outside allowed values (1, 2 or 3),"
207  << " returning zero..." << endl;
208 #endif
209  return 0; } }
210 
211 public:
212  // === Modification Methods =====================================
213 
223  // do not use rotate to avoid unusefull checks
224  Orientation += (Orientation > 0 ? - M_PI : M_PI);
225  return *this; }
226 
227 
228  // === Operators ================================================
229 
239  bool operator==(const OrPtConfig& other) const {
240  return( ( position() == other.position() ) &&
241  isParallelTo(other) ); }
242 
253  void operator+=(const OrPtConfig& other) { *this = *this + other; }
254 
269  OrPtConfig operator+(const OrPtConfig& other) const {
270  const double theta = orientation();
272  return( OrPtConfig(position() + v.rotate(theta),
273  other.orientation() + theta) );
274  } // end of OrPtConfig operator+(const OrPtConfig&)
275 
276 
277  // === Various Methods ==========================================
278 
289  { OrPtConfig res(*this); return res.uTurn(); }
290 
291 
307  double distance2(const OrPtConfig& other) const
308  { return( position().distance( other.position() ) ); }
309 
310 
323  bool isParallelTo(const OrPtConfig& other) const
324  { return( isZero( mod2pi( orientation() -
325  other.orientation() ) ) ); }
326 
343  bool isSymmetricTo(const OrPtConfig& other) const
344  // Cf. end of doc. comment
345  { return( isZero( ( position() - other.position() ) ^
347  other.orientation() ) / 2)
348  ) ); }
349 
364  bool isAlignedWith(const OrPtConfig& other) const
365  { return( isParallelTo(other) && isSymmetricTo(other) ); }
366 
367 
387  bool hasInFront(const iSeeML::geom::Point& point) const
388  // Cf. end of doc. comment
389  { return( ( point - position() ) *
390  geom::Vector( orientation() ) >= 0 ); }
391 
392 }; // end of class iSeeML::rob::OrPtConfig
393 
394 #endif // end of definition
395 
double algCoord(const int i) const
Description method, giving the coordinate of given index of the configuration (both coordinates of th...
Definition: OrPtConfig.hpp:200
bool isSymmetricTo(const OrPtConfig &other) const
Various method, checking whether two oriented points are symmetric, ie whether their orientations are...
Definition: OrPtConfig.hpp:343
iSeeML::Object & clone() const
Description method, giving a copy of the current configuration.
Definition: OrPtConfig.hpp:113
const iSeeML::geom::Point & position() const
Description method, giving the position of the robot&#39;s reference point in this configuration.
Definition: OrPtConfig.hpp:132
This class defines 2D geometric vectors, which can be defined by their Polar or Cartesian coordinates...
Definition: Vector.hpp:34
This class is the base class of ISeeML: every class of ISeeML inherits this one.
Definition: Object.hpp:47
const double & xCoord() const
Description method, giving the point&#39;s first coordinate.
Definition: Point.hpp:90
OrPtConfig()
The default constructor should only be used for array initializations: it correspond to a default poi...
Definition: OrPtConfig.hpp:67
static const string ClassName
The class name is public, as this class can be instanced.
Definition: OrPtConfig.hpp:56
bool isAlignedWith(const OrPtConfig &other) const
Various method, checking whether two oriented points are aligned: their orientations should be equal...
Definition: OrPtConfig.hpp:364
Vector & rotate(const double &theta)
Modification method, rotating the vector of a given angle.
Definition: Vector.hpp:245
This class defines a standard robotic configuration, containing the position of a reference point and...
Definition: OrPtConfig.hpp:45
iSeeML::geom::Vector projection(const iSeeML::geom::Point &P) const
Gives the projection of a point in the frame of this configuration.
Definition: OrPtConfig.hpp:151
double distance2(const OrPtConfig &other) const
Various method, giving the distance between two oriented points&#39; positions.
Definition: OrPtConfig.hpp:307
virtual void algWriteTo(ostream &O) const
Description method for algebraic vectors, writing this vector in a given output stream: coordinates f...
Definition: Object.hpp:161
OrPtConfig projection(const OrPtConfig &q) const
Projects a configuration in the frame of this configuration.
Definition: OrPtConfig.hpp:168
This class is the base class of robotic namespace of ISeeML: every robotic object inherits this one...
Definition: Object.hpp:21
bool operator==(const OrPtConfig &other) const
Equality operator between oriented points.
Definition: OrPtConfig.hpp:239
bool hasInFront(const iSeeML::geom::Point &point) const
Various method, checking whether a point is in the front half-plane of the current oriented point: th...
Definition: OrPtConfig.hpp:387
This class defines 2D geometric points, defined by their Cartesian coordinates.
Definition: Point.hpp:29
const double & orientation() const
Description method, giving the orientation of the robot&#39;s main axis in this configuration.
Definition: OrPtConfig.hpp:139
void operator+=(const OrPtConfig &other)
Adds an oriente point to the current one: gives the oriented point obtained when the added oriented p...
Definition: OrPtConfig.hpp:253
bool isParallelTo(const OrPtConfig &other) const
Various method, checking whether two oriented points are parallel, ie whether their orientations are ...
Definition: OrPtConfig.hpp:323
OrPtConfig opposite() const
Various method, giving the opposite oriented point of the current one: the opposite oriented point ha...
Definition: OrPtConfig.hpp:288
int algDimension() const
Description method, giving the dimension of the containing space (3) when this configuration is consi...
Definition: OrPtConfig.hpp:182
OrPtConfig(const double &x, const double &y, const double &theta)
A usefull constructor.
Definition: OrPtConfig.hpp:92
OrPtConfig operator+(const OrPtConfig &other) const
Addition operator between oriented points: gives the oriented point obtained when the second oriented...
Definition: OrPtConfig.hpp:269
static bool isZero(const double &x)
Method comparing a double to zero.
Definition: Object.hpp:288
void writeTo(ostream &O) const
Description method, writing the configuration in a given output stream: coordinate in each dimension ...
Definition: OrPtConfig.hpp:124
virtual ~OrPtConfig()
The virtual destructor does nothing.
Definition: OrPtConfig.hpp:100
OrPtConfig(const iSeeML::geom::Point &P, const double &theta)
The main constructor.
Definition: OrPtConfig.hpp:78
static double mod2pi(const double &theta)
Method giving the angle between - (excluded) and (included), which is equal to a given angle modulo...
Definition: Object.hpp:232
OrPtConfig & uTurn()
Modification method, turning the current oriented point to its opposite: the position does not change...
Definition: OrPtConfig.hpp:222
const double & yCoord() const
Description method, giving the point&#39;s second coordinate.
Definition: Point.hpp:96