Geom.h
Go to the documentation of this file.
1 
6 #include <cmath>
7 #include <vector>
8 #include <string>
9 #include <cstddef>
10 #include <tuple>
11 
12 #include "Const.h"
13 
14 #ifndef ORCA_GEOM_H
15 #define ORCA_GEOM_H
16 
21 class Node
22 {
23  public:
24  int i;
25  int j;
26  double g;
27  double H;
28  double F;
30 
39  Node(int i = 0, int j = 0, Node *p = nullptr, double g = 0, double h = 0)
40  : i(i), j(j), g(g), H(h), F(g+h), parent(p){}
41 
47  bool operator != (const Node &other) const ;
48 
54  bool operator == (const Node &another) const;
55 };
56 
61 class Point
62 {
63  public:
67  Point();
68 
74  Point(float x, float y);
75 
80  Point(const Point &obj);
81 
85  virtual ~Point() = default;
86 
91  float X() const;
92 
97  float Y() const;
98 
103  std::pair<float, float> GetPair();
104 
110  float ScalarProduct(const Point &another) const;
111 
116  float EuclideanNorm() const;
117 
122  float SquaredEuclideanNorm() const;
123 
133  float Det(Point another) const;
134 
139  std::string ToString() const;
140 
146  Point operator - (const Point &another) const;
147 
153  Point operator + (const Point &another) const;
154 
160  bool operator == (const Point &another) const;
161 
167  Point operator * (float k) const;
168 
174  Point operator / (float k) const;
175 
180  Point operator - () const;
181 
187  virtual Point & operator = (const Point &obj);
188 
189 
190 
191  private:
192  float x;
193  float y;
194 };
195 
196 
202 class Line
203 {
204  public:
207 };
208 
213 class Vertex : public Point
214 {
215  public:
219  Vertex() : Point() {}
220 
227  Vertex(float x, float y, bool cvx = false) : Point(x, y), convex(cvx) {}
228 
234  Vertex(const Point &obj, bool cvx = false) : Point(obj), convex(cvx) {}
235 
240  Vertex(const Vertex &obj) : Point(obj), convex(obj.convex) {}
241 
245  ~Vertex() override = default;
246 
251  bool IsConvex() const;
252 
257  void SetConvex(bool cvx);
258 
264  Vertex & operator = (const Vertex &obj);
265 
266  private:
267  bool convex;
268 };
269 
275 {
276  public:
280  ObstacleSegment() = default;
281 
286  ObstacleSegment(const ObstacleSegment &obj) : left(obj.left), right(obj.right), id(obj.id), next(obj.next), prev(obj.prev), dir(obj.dir) {}
287 
295  ObstacleSegment(int id, const Vertex &left, const Vertex &right) : left(left), right(right), id(id) {dir = right-left; dir = dir/dir.EuclideanNorm();}
296 
300  ~ObstacleSegment() = default;
301 
307  bool operator == (const ObstacleSegment &another) const;
308 
314  ObstacleSegment & operator = (const ObstacleSegment &obj);
315 
316 
317  int id;
323 
324 };
325 
329 namespace Utils
330 {
339  float SqPointSegDistance(Point L1, Point L2, Point P);
340 
354  bool linearProgram1(const std::vector<Line> &lines, unsigned long curr, float radius, const Vector &optVelocity,
355  bool directionOpt, Vector &result);
356 
368  unsigned long int linearProgram2(const std::vector<Line> &lines, float radius, const Vector &optVelocity,
369  bool directionOpt, Vector &result);
370 
381  void linearProgram3(const std::vector<Line> &lines, size_t numObstLines, size_t beginLine,
382  float radius, Vector &result);
383 
384 
385  template<typename T>
392  bool More( std::pair<float, T> a, std::pair<float, T> b)
393  {
394  return (a.first > b.first);
395  }
396 
397  template<typename T>
404  bool Less( std::pair<float, T> a, std::pair<float, T> b)
405  {
406  return (a.first < b.first);
407  }
408 };
409 
410 
411 
412 
413 
414 /*********************************************************
415  * Methods Implementations *
416  *********************************************************/
417 
418 
419 inline bool Node::operator == (const Node &another) const
420 {
421  return i == another.i && j == another.j;
422 }
423 
424 inline bool Node::operator != (const Node &other) const
425 {
426  return i != other.i || j != other.j;
427 }
428 
429 
430 
431 
432 inline bool ObstacleSegment::operator ==(const ObstacleSegment &another) const
433 {
434  return (this->id == another.id);
435 }
436 
438 {
439 
440  id = obj.id;
441  left = obj.left;
442  right = obj.right;
443  dir = obj.dir;
444  next = obj.next;
445  prev = obj.prev;
446  return *this;
447 }
448 
449 inline float Point::ScalarProduct(const Point &another) const
450 {
451  return this->x * another.x + this->y * another.y;
452 }
453 
454 
455 inline Point Point::operator - (const Point &another) const
456 {
457  return {this->x - another.x, this->y - another.y};
458 }
459 
460 
461 inline Point Point::operator + (const Point &another) const
462 {
463  return {this->x + another.x, this->y + another.y};
464 }
465 
466 
467 inline Point Point::operator * (float k) const
468 {
469  return {this->x * k, this->y * k};
470 }
471 
472 
473 inline Point Point::operator /(float k) const
474 {
475  const float invK = 1.0f / k;
476  return {this->x * invK, this->y * invK};
477 }
478 
479 
480 inline float Point::SquaredEuclideanNorm() const
481 {
482  return this->ScalarProduct(*this);
483 }
484 
485 
486 inline float Point::EuclideanNorm() const
487 {
488  return std::sqrt(this->ScalarProduct(*this));
489 }
490 
491 
492 inline float Point::Det(Point another) const
493 {
494  return (this->x * another.y - this->y * another.x);
495 }
496 
497 
498 inline bool Point::operator ==(const Point &another) const
499 {
500  return (this->x == another.x) && (this->y == another.y);
501 }
502 
503 
504 inline Point Point::operator-() const
505 {
506  return Point(-this->x, -this->y);
507 }
508 
509 
510 inline Point& Point::operator = (const Point &obj)
511 {
512  x = obj.x;
513  y = obj.y;
514  return *this;
515 }
516 
517 
518 inline Vertex& Vertex::operator = (const Vertex &obj)
519 {
520  Point::operator=(obj);
521  convex = obj.convex;
522  return *this;
523 }
524 
525 
526 
527 #endif //ORCA_GEOM_H
ObstacleSegment & operator=(const ObstacleSegment &obj)
Assignment operator.
Definition: Geom.h:437
float SquaredEuclideanNorm() const
Computes squared euclidean norm of vector.
Definition: Geom.h:480
Node(int i=0, int j=0, Node *p=nullptr, double g=0, double h=0)
Node constructor with parameters.
Definition: Geom.h:39
Vector dir
Vector (right-left)/|right-left|.
Definition: Geom.h:320
bool linearProgram1(const std::vector< Line > &lines, unsigned long curr, float radius, const Vector &optVelocity, bool directionOpt, Vector &result)
Solves a one-dimensional linear program on a specified line subject to linear constraints defined by ...
Definition: Geom.cpp:88
Point operator/(float k) const
operator /
Definition: Geom.h:473
Vector dir
direction vector of line.
Definition: Geom.h:205
Point operator*(float k) const
operator *
Definition: Geom.h:467
The Node class defines a cell of grid (see Map class)
Definition: Geom.h:21
The class defines a line in 2D space.
Definition: Geom.h:202
Point operator-() const
operator -
Definition: Geom.h:504
ObstacleSegment * prev
Previous edge in obstacle.
Definition: Geom.h:322
Point operator+(const Point &another) const
operator +
Definition: Geom.h:461
bool More(std::pair< float, T > a, std::pair< float, T > b)
Comparison function for pairs of the form <float, T> For sorting purposes.
Definition: Geom.h:392
double g
g-value of node for A* based algorithms.
Definition: Geom.h:26
The ObstacleSegment class defines an edge of an obstacle polygon.
Definition: Geom.h:274
int id
Identifier of edge.
Definition: Geom.h:317
bool operator==(const Point &another) const
operator ==
Definition: Geom.h:498
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
Definition: Geom.h:61
Vertex()
Vertex default constructor.
Definition: Geom.h:219
Vertex & operator=(const Vertex &obj)
Assignment operator.
Definition: Geom.h:518
#define Vector
Vector type definition.
Definition: Const.h:11
float x
X-coordinate of the point.
Definition: Geom.h:192
float EuclideanNorm() const
Computes euclidean norm of vector.
Definition: Geom.h:486
Vertex left
Left vertex of edge (when viewed from the outside of an obstacle).
Definition: Geom.h:318
Vertex(float x, float y, bool cvx=false)
Vertex constructor.
Definition: Geom.h:227
bool operator!=(const Node &other) const
operator !=
Definition: Geom.h:424
ObstacleSegment(int id, const Vertex &left, const Vertex &right)
ObstacleSegment constructor.
Definition: Geom.h:295
Vertex(const Vertex &obj)
Vertex copy constructor.
Definition: Geom.h:240
virtual Point & operator=(const Point &obj)
Assignment operator.
Definition: Geom.h:510
ObstacleSegment(const ObstacleSegment &obj)
Copy constructor.
Definition: Geom.h:286
double F
F = g + h. Value for A* based algorithms.
Definition: Geom.h:28
float Det(Point another) const
Computes the determinant of matrix.
Definition: Geom.h:492
int i
The number of row. Part of (i,j) address of cell on grid.
Definition: Geom.h:24
File contains main constants.
void linearProgram3(const std::vector< Line > &lines, size_t numObstLines, size_t beginLine, float radius, Vector &result)
Solves a two-dimensional linear program subject to linear constraints defined by lines and a circular...
Definition: Geom.cpp:214
float y
Y-coordinate of the point.
Definition: Geom.h:193
bool convex
Convexity of vertex.
Definition: Geom.h:267
float ScalarProduct(const Point &another) const
Computes scalar product of vectors (this * anoher)
Definition: Geom.h:449
ObstacleSegment * next
Next edge in obstacle.
Definition: Geom.h:321
unsigned long int linearProgram2(const std::vector< Line > &lines, float radius, const Vector &optVelocity, bool directionOpt, Vector &result)
Solves a two-dimensional linear program subject to linear constraints defined by lines and a circular...
Definition: Geom.cpp:179
Vertex right
Right vertex of edge (when viewed from the outside of an obstacle).
Definition: Geom.h:319
Vertex(const Point &obj, bool cvx=false)
Vertex constructor.
Definition: Geom.h:234
bool operator==(const ObstacleSegment &another) const
operator ==
Definition: Geom.h:432
int j
The number of column. Part of (i,j) address of cell on grid.
Definition: Geom.h:25
The set of utility functions.
Definition: Geom.h:329
float SqPointSegDistance(Point L1, Point L2, Point P)
Computes squared euclidean distance from point to line segment.
Definition: Geom.cpp:68
Node * parent
The node from which the transition to this node was made. Value for A* based algorithms.
Definition: Geom.h:29
Point liesOn
point on line.
Definition: Geom.h:206
The Vertex class defines a vertex of an obstacle polygon.
Definition: Geom.h:213
bool Less(std::pair< float, T > a, std::pair< float, T > b)
Comparison function for pairs of the form <float, T> For sorting purposes.
Definition: Geom.h:404
double H
h-value of node for A* based algorithms.
Definition: Geom.h:27
bool operator==(const Node &another) const
operator ==
Definition: Geom.h:419


ORCAStar
Author(s): Stepan Drgachev
autogenerated on Wed Jul 15 2020 16:13:14