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:
184  int algDimension() const { return 3; }
185 
202  double algCoord(const int i) const {
203  switch (i) { case 1: return position().xCoord();
204  case 2: return position().yCoord();
205  case 3: return orientation(); default:
206 #ifdef ISEEML_CHECK_ORPT_CONFIG_PRECOND
207  cerr << ClassName << "::coord: parameter " << i << endl
208  << " outside allowed values (1, 2 or 3),"
209  << " returning zero..." << endl;
210 #endif
211  return 0; } }
212 
213 public:
214  // === Modification Methods =====================================
215 
225  // do not use rotate to avoid unusefull checks
226  Orientation += (Orientation > 0 ? - M_PI : M_PI);
227  return *this; }
228 
229 
230  // === Operators ================================================
231 
241  bool operator==(const OrPtConfig& other) const {
242  return( ( position() == other.position() ) &&
243  isParallelTo(other) ); }
244 
255  void operator+=(const OrPtConfig& other) { *this = *this + other; }
256 
271  OrPtConfig operator+(const OrPtConfig& other) const {
272  const double theta = orientation();
274  return( OrPtConfig(position() + v.rotate(theta),
275  other.orientation() + theta) );
276  } // end of OrPtConfig operator+(const OrPtConfig&)
277 
278 
279  // === Various Methods ==========================================
280 
291  { OrPtConfig res(*this); return res.uTurn(); }
292 
293 
309  double distance2(const OrPtConfig& other) const
310  { return( position().distance( other.position() ) ); }
311 
312 
325  bool isParallelTo(const OrPtConfig& other) const
326  { return( isZero( mod2pi( orientation() -
327  other.orientation() ) ) ); }
328 
345  bool isSymmetricTo(const OrPtConfig& other) const
346  // Cf. end of doc. comment
347  { return( isZero( ( position() - other.position() ) ^
349  other.orientation() ) / 2)
350  ) ); }
351 
366  bool isAlignedWith(const OrPtConfig& other) const
367  { return( isParallelTo(other) && isSymmetricTo(other) ); }
368 
369 
389  bool hasInFront(const iSeeML::geom::Point& point) const
390  // Cf. end of doc. comment
391  { return( ( point - position() ) *
392  geom::Vector( orientation() ) >= 0 ); }
393 
394 }; // end of class iSeeML::rob::OrPtConfig
395 
396 #endif // end of definition
397 
iSeeML::rob::OrPtConfig::writeTo
void writeTo(ostream &O) const
Description method, writing the configuration in a given output stream: coordinate in each dimension ...
Definition: OrPtConfig.hpp:124
iSeeML::rob::OrPtConfig::operator==
bool operator==(const OrPtConfig &other) const
Equality operator between oriented points.
Definition: OrPtConfig.hpp:241
iSeeML::Object::algWriteTo
virtual void algWriteTo(ostream &O) const
Description method for algebraic vectors, writing this vector in a given output stream: coordinates f...
Definition: Object.hpp:166
iSeeML::rob::OrPtConfig::projection
OrPtConfig projection(const OrPtConfig &q) const
Projects a configuration in the frame of this configuration.
Definition: OrPtConfig.hpp:168
iSeeML::rob::OrPtConfig::OrPtConfig
OrPtConfig(const iSeeML::geom::Point &P, const double &theta)
The main constructor.
Definition: OrPtConfig.hpp:78
iSeeML::rob::OrPtConfig::clone
iSeeML::Object & clone() const
Description method, giving a copy of the current configuration.
Definition: OrPtConfig.hpp:113
iSeeML::rob::OrPtConfig::algDimension
int algDimension() const
Description method, giving the dimension of the containing space (3) when this configuration is consi...
Definition: OrPtConfig.hpp:184
iSeeML::rob::OrPtConfig::projection
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
iSeeML::geom::Point::yCoord
const double & yCoord() const
Description method, giving the point's second coordinate.
Definition: Point.hpp:96
iSeeML::rob::OrPtConfig::orientation
const double & orientation() const
Description method, giving the orientation of the robot's main axis in this configuration.
Definition: OrPtConfig.hpp:139
iSeeML::rob::OrPtConfig::isSymmetricTo
bool isSymmetricTo(const OrPtConfig &other) const
Various method, checking whether two oriented points are symmetric, ie whether their orientations are...
Definition: OrPtConfig.hpp:345
iSeeML::geom::Point::xCoord
const double & xCoord() const
Description method, giving the point's first coordinate.
Definition: Point.hpp:90
iSeeML::rob::OrPtConfig
This class defines a standard robotic configuration, containing the position of a reference point and...
Definition: OrPtConfig.hpp:45
iSeeML::rob::OrPtConfig::operator+=
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:255
iSeeML::rob::OrPtConfig::ClassName
static const string ClassName
The class name is public, as this class can be instanced.
Definition: OrPtConfig.hpp:56
iSeeML::Object::mod2pi
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:252
iSeeML::rob::OrPtConfig::position
const iSeeML::geom::Point & position() const
Description method, giving the position of the robot's reference point in this configuration.
Definition: OrPtConfig.hpp:132
iSeeML::geom::Vector::rotate
Vector & rotate(const double &theta)
Modification method, rotating the vector of a given angle.
Definition: Vector.hpp:247
iSeeML::rob::OrPtConfig::uTurn
OrPtConfig & uTurn()
Modification method, turning the current oriented point to its opposite: the position does not change...
Definition: OrPtConfig.hpp:224
iSeeML::rob::OrPtConfig::isParallelTo
bool isParallelTo(const OrPtConfig &other) const
Various method, checking whether two oriented points are parallel, ie whether their orientations are ...
Definition: OrPtConfig.hpp:325
iSeeML::Object::isZero
static bool isZero(const double &x)
Method comparing a double to zero.
Definition: Object.hpp:312
iSeeML::rob::OrPtConfig::distance2
double distance2(const OrPtConfig &other) const
Various method, giving the distance between two oriented points' positions.
Definition: OrPtConfig.hpp:309
iSeeML::rob::OrPtConfig::~OrPtConfig
virtual ~OrPtConfig()
The virtual destructor does nothing.
Definition: OrPtConfig.hpp:100
iSeeML::geom::Vector
This class defines 2D geometric vectors, which can be defined by their Polar or Cartesian coordinates...
Definition: Vector.hpp:34
iSeeML::Object
This class is the base class of ISeeML: every class of ISeeML inherits this one.
Definition: Object.hpp:47
iSeeML::rob::OrPtConfig::hasInFront
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:389
iSeeML::rob::OrPtConfig::isAlignedWith
bool isAlignedWith(const OrPtConfig &other) const
Various method, checking whether two oriented points are aligned: their orientations should be equal,...
Definition: OrPtConfig.hpp:366
iSeeML::rob::Object
This class is the base class of robotic namespace of ISeeML: every robotic object inherits this one.
Definition: Object.hpp:21
iSeeML::rob::OrPtConfig::operator+
OrPtConfig operator+(const OrPtConfig &other) const
Addition operator between oriented points: gives the oriented point obtained when the second oriented...
Definition: OrPtConfig.hpp:271
iSeeML::geom::Point
This class defines 2D geometric points, defined by their Cartesian coordinates.
Definition: Point.hpp:29
iSeeML::rob::OrPtConfig::OrPtConfig
OrPtConfig()
The default constructor should only be used for array initializations: it correspond to a default poi...
Definition: OrPtConfig.hpp:67
iSeeML::rob::OrPtConfig::opposite
OrPtConfig opposite() const
Various method, giving the opposite oriented point of the current one: the opposite oriented point ha...
Definition: OrPtConfig.hpp:290
iSeeML::rob::OrPtConfig::OrPtConfig
OrPtConfig(const double &x, const double &y, const double &theta)
A usefull constructor.
Definition: OrPtConfig.hpp:92
iSeeML::rob::OrPtConfig::algCoord
double algCoord(const int i) const
Description method, giving the coordinate of given index of the configuration (both coordinates of th...
Definition: OrPtConfig.hpp:202