MRPT  2.0.4
TPolygon2D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10
11 #include <mrpt/math/TPoint2D.h>
12 #include <mrpt/math/TPoseOrPoint.h>
13 #include <vector>
14
15 namespace mrpt::math
16 {
17 /**
18  * 2D polygon, inheriting from std::vector<TPoint2D>.
19  * \sa TPolygon3D,TSegment2D,TLine2D,TPoint2D, CPolygon
20  */
21 class TPolygon2D : public std::vector<TPoint2D>
22 {
23  public:
24  /** Distance to a point (always >=0) */
25  double distance(const TPoint2D& point) const;
26  /** Check whether a point is inside (or within geometryEpsilon of a polygon
27  * edge). This works for concave or convex polygons. */
28  bool contains(const TPoint2D& point) const;
29  /** Gets as set of segments, instead of points. */
30  void getAsSegmentList(std::vector<TSegment2D>& v) const;
31  /** Projects into 3D space, zeroing the z. */
32  void generate3DObject(TPolygon3D& p) const;
33  /** Polygon's central point. */
34  void getCenter(TPoint2D& p) const;
35  /** Checks whether is convex. */
36  bool isConvex() const;
37  /** Erase repeated vertices. \sa removeRedundantVertices */
39  /** Erase every redundant vertex from the polygon, saving space. \sa
40  * removeRepeatedVertices */
42  /** Gets plot data, ready to use on a 2D plot. \sa
43  * mrpt::gui::CDisplayWindowPlots */
44  void getPlotData(std::vector<double>& x, std::vector<double>& y) const;
45  /** Get polygon bounding box. \exception On empty polygon */
46  void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const;
47  /** Default constructor */
48  TPolygon2D() : std::vector<TPoint2D>() {}
49  /** Constructor for a given number of vertices, intializing them as garbage.
50  */
51  explicit TPolygon2D(size_t N) : std::vector<TPoint2D>(N) {}
52  /** Implicit constructor from a vector of 2D points */
53  TPolygon2D(const std::vector<TPoint2D>& v) : std::vector<TPoint2D>(v) {}
54  /** Constructor from a 3D object. */
55  explicit TPolygon2D(const TPolygon3D& p);
56  /** Static method to create a regular polygon, given its size and radius.
57  * \throw std::logic_error if radius is near zero or the number of edges is
58  * less than three.
59  */
60  static void createRegularPolygon(
61  size_t numEdges, double radius, TPolygon2D& poly);
62  /** Static method to create a regular polygon from its size and radius. The
63  * center will correspond to the given pose.
64  * \throw std::logic_error if radius is near zero or the number of edges is
65  * less than three.
66  */
67  static void createRegularPolygon(
68  size_t numEdges, double radius, TPolygon2D& poly,
69  const mrpt::math::TPose2D& pose);
70 };
71
72 } // namespace mrpt::math
73
74 namespace mrpt::typemeta
75 {
76 // Specialization must occur in the same namespace
78 } // namespace mrpt::typemeta
static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D &poly)
Static method to create a regular polygon, given its size and radius.
Definition: TPolygon2D.cpp:166
void getCenter(TPoint2D &p) const
Polygon&#39;s central point.
Definition: TPolygon2D.cpp:110
STL namespace.
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
Definition: TPolygon2D.cpp:69
void removeRepeatedVertices()
Erase repeated vertices.
Definition: TPolygon2D.cpp:140
void removeRedundantVertices()
Erase every redundant vertex from the polygon, saving space.
Definition: TPolygon2D.cpp:141
This base provides a set of functions for maths stuff.
void getAsSegmentList(std::vector< TSegment2D > &v) const
Gets as set of segments, instead of points.
Definition: TPolygon2D.cpp:97
bool isConvex() const
Checks whether is convex.
Definition: TPolygon2D.cpp:117
double distance(const TPoint2D &point) const
Distance to a point (always >=0)
Definition: TPolygon2D.cpp:22
void getPlotData(std::vector< double > &x, std::vector< double > &y) const
Gets plot data, ready to use on a 2D plot.
Definition: TPolygon2D.cpp:146
TPolygon2D()
Default constructor.
Definition: TPolygon2D.h:48
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
TPolygon2D(size_t N)
Constructor for a given number of vertices, intializing them as garbage.
Definition: TPolygon2D.h:51
void getBoundingBox(TPoint2D &min_coords, TPoint2D &max_coords) const
Get polygon bounding box.
Definition: TPolygon2D.cpp:41
Lightweight 2D pose.
Definition: TPose2D.h:22
void generate3DObject(TPolygon3D &p) const
Projects into 3D space, zeroing the z.
Definition: TPolygon2D.cpp:106
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
TPolygon2D(const std::vector< TPoint2D > &v)
Implicit constructor from a vector of 2D points.
Definition: TPolygon2D.h:53

 Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 7b5ddf9de Fri May 29 14:02:56 2020 +0200 at vie may 29 14:15:09 CEST 2020 