MRPT  1.9.9
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-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
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.
void getPlotData(std::vector< double > &x, std::vector< double > &y) const
Gets plot data, ready to use on a 2D plot.
void getAsSegmentList(std::vector< TSegment2D > &v) const
Gets as set of segments, instead of points.
STL namespace.
void removeRepeatedVertices()
Erase repeated vertices.
void generate3DObject(TPolygon3D &p) const
Projects into 3D space, zeroing the z.
void getBoundingBox(TPoint2D &min_coords, TPoint2D &max_coords) const
Get polygon bounding box.
This base provides a set of functions for maths stuff.
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
void getCenter(TPoint2D &p) const
Polygon&#39;s central point.
TPolygon2D(size_t N)
Constructor for a given number of vertices, intializing them as garbage.
Definition: TPolygon2D.h:51
bool isConvex() const
Checks whether is convex.
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
double distance(const TPoint2D &point) const
Distance to a point (always >=0)
const GLdouble * v
Definition: glext.h:3684
Lightweight 2D pose.
Definition: TPose2D.h:22
void removeRedundantVertices()
Erase every redundant vertex from the polygon, saving space.
GLenum GLint GLint y
Definition: glext.h:3542
GLenum GLint x
Definition: glext.h:3542
Lightweight 2D point.
Definition: TPoint2D.h:31
GLfloat GLfloat p
Definition: glext.h:6398
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:18
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 1.9.9 Git: 479715d5b Tue Nov 12 07:26:21 2019 +0100 at mar nov 12 07:30:12 CET 2019