Polygon2D.hpp
Go to the documentation of this file.
1 // This is -*-c++-*-
2 //
3 
4 #ifndef POLYGON2D_HPP
5 #define POLYGON2D_HPP
6 
7 #include "../BasicDatatypes.hpp"
8 #include "Point2D.hpp"
9 #include <iosfwd> // for istream, ostream
10 #include <vector>
11 #include <sstream>
12 
13 
14 namespace datatypes
15 {
16 
17 class Line2D;
18 class Ellipse2D;
19 class Box2D;
20 
21 
43 class Polygon2D : public std::vector<Point2D>,
44  public BasicData
45 {
46 public:
48  typedef std::vector<Point2D> base_class;
49 
53 
55  Polygon2D();
56 
58  Polygon2D(const Point2D&);
59 
61  Polygon2D(const Point2D&, const Point2D&);
62 
64  Polygon2D(const Point2D&, const Point2D&, const Point2D&);
65 
67  Polygon2D(const Point2D&, const Point2D&, const Point2D&, const Point2D&);
68 
70  Polygon2D(const Line2D&);
71 
73  Polygon2D(const base_class&);
74 
76  Polygon2D(const std::string& polygonAsString);
77 
78  // Estimate the memory usage of this object
79  inline virtual const UINT32 getUsedMemory() const {return ((sizeof(*this)) + sizeof(Point2D)*size());};
80 
83  static const char* getSeparatorCharacters();
84 
86  static Polygon2D fromCircle( const Point2D& center, const floatingpoint_type radius, const UINT32 samplingPoints = 32 );
87 
89  static Polygon2D fromEllipse( const Point2D& center, const floatingpoint_type a, const floatingpoint_type b, const floatingpoint_type angle, const UINT32 samplingPoints = 32 );
90 
92  static Polygon2D fromEllipse(const Ellipse2D& ellipse, const UINT32 samplingPoints = 32 );
93 
95 
122  static Polygon2D fromArc(const Ellipse2D& ellipse,
123  const floatingpoint_type startAngle, const floatingpoint_type endAngle,
124  const UINT32 samplingPoints, const bool clockwise);
125 
127 
169  static Polygon2D fromArc(const Ellipse2D& ellipse,
170  const floatingpoint_type startAngle, const floatingpoint_type endAngle,
171  const UINT32 samplingPoints = 32);
172 
174  static Polygon2D rhombus(const Point2D& center, const floatingpoint_type radius);
175 
191  static Polygon2D createRectangle(const Point2D& lowerLeft, const Point2D& upperRight);
192 
197  //\{
205  Polygon2D& append(const Polygon2D& other);
206 
214  Polygon2D& append(const Point2D& point);
215 
223  Polygon2D& append(floatingpoint_type x, floatingpoint_type y);
224  //\}
225 
227  //\{
228 
242  bool isClosed() const;
243 
249  double getArea() const;
250 
257  Point2D getCenterOfGravity() const;
258 
268  Polygon2D getSimplified() const;
269 
271 
276  Box2D getBoundingBox() const;
277 
286  std::pair<floatingpoint_type, floatingpoint_type> getBoundingAngles() const;
287 
288  //\}
289 
291  //\{
292 
295  bool containsPoint(const Point2D& point) const;
296 
298 
308  Point2D::value_type distanceToPoint(const Point2D& point) const;
309 
317  bool isColliding(const Polygon2D& p2) const;
318 
320 
330  base_class isIntersecting(const Line2D& other) const;
331 
332  //\}
333 
334 
336 
340  std::string toString() const;
341 
342 
343 };
344 
345 
346 
347 
349 std::ostream& operator<<(std::ostream& os, const Polygon2D& point);
350 
351 
352 } // namespace datatypes
353 
354 #endif
bool isColliding(const Polygon2D &p2) const
Returns true if the given polygon collides with this polygon.
Definition: Polygon2D.cpp:492
static Polygon2D createRectangle(const Point2D &lowerLeft, const Point2D &upperRight)
Definition: Polygon2D.cpp:248
std::string toString() const
Text output for debugging.
Definition: Polygon2D.cpp:584
bool containsPoint(const Point2D &point) const
Returns true if the given Point2D is inside this polygon.
Definition: Polygon2D.cpp:420
A rotated 2-dimensional box in the plane.
Definition: Box2D.hpp:34
Point2D getCenterOfGravity() const
Returns the center of gravity of this polygon.
Definition: Polygon2D.cpp:108
Box2D getBoundingBox() const
Returns a Box in parallel to the coordinate system that bounds this polygon.
Definition: Polygon2D.cpp:277
Polygon2D getSimplified() const
Returns a polygon with potentially less edge points.
Definition: Polygon2D.cpp:552
uint32_t UINT32
Point2D::value_type floatingpoint_type
Definition: Polygon2D.hpp:52
A polygon of 2D-points.
Definition: Polygon2D.hpp:43
Polygon2D()
Constructor for an empty polygon.
Definition: Polygon2D.cpp:23
std::pair< floatingpoint_type, floatingpoint_type > getBoundingAngles() const
Definition: Polygon2D.cpp:306
static Polygon2D rhombus(const Point2D &center, const floatingpoint_type radius)
Static function to create a rhombus.
Definition: Polygon2D.cpp:236
Polygon2D & append(const Polygon2D &other)
Appends the points of the other polygon to this polygon.
Definition: Polygon2D.cpp:72
bool isClosed() const
Returns true if this is explicitly a closed polygon.
Definition: Polygon2D.cpp:127
static Polygon2D fromArc(const Ellipse2D &ellipse, const floatingpoint_type startAngle, const floatingpoint_type endAngle, const UINT32 samplingPoints, const bool clockwise)
(DEPRECATED) Create a Polygon2D approximation of the arc of an ellipse
Definition: Polygon2D.cpp:162
base_class isIntersecting(const Line2D &other) const
Calculates all intersection points between a line and this polygon.
Definition: Polygon2D.cpp:517
A line in the two-dimensional plane, composed out of two points.
Definition: Line2D.hpp:24
double value_type
The type of the stored x and y coordinates.
Definition: Point2D.hpp:31
static Polygon2D fromEllipse(const Point2D &center, const floatingpoint_type a, const floatingpoint_type b, const floatingpoint_type angle, const UINT32 samplingPoints=32)
Static function to create a Polygon2D from ellipse parameters.
Definition: Polygon2D.cpp:144
static Polygon2D fromCircle(const Point2D &center, const floatingpoint_type radius, const UINT32 samplingPoints=32)
Static function to get Polygon2D from circle parameters.
Definition: Polygon2D.cpp:138
A rotated 2-dimensional ellipse in the plane.
Definition: Ellipse2D.hpp:30
static const char * getSeparatorCharacters()
Definition: Polygon2D.cpp:231
virtual const UINT32 getUsedMemory() const
Definition: Polygon2D.hpp:79
Point2D::value_type distanceToPoint(const Point2D &point) const
Returns the distance of a point to this polyon.
Definition: Polygon2D.cpp:535
std::vector< Point2D > base_class
The base type. (Naming according to boost convention.)
Definition: Polygon2D.hpp:48
double getArea() const
Returns the area enclosed by this polygon.
Definition: Polygon2D.cpp:90
std::ostream & operator<<(std::ostream &os, const EvalCaseResult &result)


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Sat Jun 8 2019 17:57:33