MRPT  2.0.1
TPolygon3D.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 |
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/TPoint3D.h>
12 #include <mrpt/math/TPoseOrPoint.h>
13 #include <vector>
14 
15 namespace mrpt::math
16 {
17 /** 3D polygon, inheriting from std::vector<TPoint3D>
18  * \sa TPolygon2D,TSegment3D,TLine3D,TPlane,TPoint3D
19  */
20 class TPolygon3D : public std::vector<TPoint3D>
21 {
22  public:
23  /** Distance to point (always >=0) */
24  double distance(const TPoint3D& point) const;
25  /** Check whether a point is inside (or within geometryEpsilon of a polygon
26  * edge). This works for concave or convex polygons. */
27  bool contains(const TPoint3D& point) const;
28  /** Gets as set of segments, instead of set of points. */
29  void getAsSegmentList(std::vector<TSegment3D>& v) const;
30  /** Gets a plane which contains the polygon. Returns false if the polygon is
31  * skew and cannot be fit inside a plane. */
32  bool getPlane(TPlane& p) const;
33  /** Gets the best fitting plane, disregarding whether the polygon actually
34  * fits inside or not. \sa getBestFittingPlane */
35  void getBestFittingPlane(TPlane& p) const;
36  /** Projects into a 2D space, discarding the z. \sa getPlane,isSkew */
37  void generate2DObject(TPolygon2D& p) const;
38  /** Get polygon's central point. */
39  void getCenter(TPoint3D& p) const;
40  /** Check whether the polygon is skew. Returns true if there doesn't exist a
41  * plane in which the polygon can fit. \sa getBestFittingPlane */
42  bool isSkew() const;
43  /** Remove polygon's repeated vertices. */
45  /** Erase every redundant vertex, thus saving space. */
47  /** Default constructor. Creates a polygon with no vertices. */
48  TPolygon3D() : std::vector<TPoint3D>() {}
49  /** Constructor for a given size. Creates a polygon with a fixed number of
50  * vertices, which are initialized to garbage. */
51  explicit TPolygon3D(size_t N) : std::vector<TPoint3D>(N) {}
52  /** Implicit constructor from a 3D points vector. */
53  TPolygon3D(const std::vector<TPoint3D>& v) : std::vector<TPoint3D>(v) {}
54  /** Constructor from a 2D object. Zeroes the z. */
55  explicit TPolygon3D(const TPolygon2D& p);
56  /** Static method to create a regular polygon, given its size and radius.
57  * \throw std::logic_error if number of edges is less than three, or radius
58  * is near zero. */
59  static void createRegularPolygon(
60  size_t numEdges, double radius, TPolygon3D& poly);
61  /** Static method to create a regular polygon, given its size and radius.
62  * The center will be located on the given pose.
63  * \throw std::logic_error if number of edges is less than three, or radius
64  * is near zero.
65  */
66  static void createRegularPolygon(
67  size_t numEdges, double radius, TPolygon3D& poly,
68  const mrpt::math::TPose3D& pose);
69 };
70 
71 } // namespace mrpt::math
72 
73 namespace mrpt::typemeta
74 {
75 // Specialization must occur in the same namespace
77 
78 } // namespace mrpt::typemeta
TPolygon3D(const std::vector< TPoint3D > &v)
Implicit constructor from a 3D points vector.
Definition: TPolygon3D.h:53
void getCenter(TPoint3D &p) const
Get polygon&#39;s central point.
Definition: TPolygon3D.cpp:81
TPolygon3D()
Default constructor.
Definition: TPolygon3D.h:48
STL namespace.
static void createRegularPolygon(size_t numEdges, double radius, TPolygon3D &poly)
Static method to create a regular polygon, given its size and radius.
Definition: TPolygon3D.cpp:102
This base provides a set of functions for maths stuff.
void removeRedundantVertices()
Erase every redundant vertex, thus saving space.
Definition: TPolygon3D.cpp:91
void getAsSegmentList(std::vector< TSegment3D > &v) const
Gets as set of segments, instead of set of points.
Definition: TPolygon3D.cpp:68
3D Plane, represented by its equation
Definition: TPlane.h:22
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
Definition: TPolygon3D.cpp:77
void removeRepeatedVertices()
Remove polygon&#39;s repeated vertices.
Definition: TPolygon3D.cpp:90
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:24
TPolygon3D(size_t N)
Constructor for a given size.
Definition: TPolygon3D.h:51
void generate2DObject(TPolygon2D &p) const
Projects into a 2D space, discarding the z.
Definition: TPolygon3D.cpp:24
bool isSkew() const
Check whether the polygon is skew.
Definition: TPolygon3D.cpp:89
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon.
Definition: TPolygon3D.cpp:76
bool contains(const TPoint3D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
Definition: TPolygon3D.cpp:43
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
double distance(const TPoint3D &point) const
Distance to point (always >=0)
Definition: TPolygon3D.cpp:29



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020