class mrpt::math::TPolygon2D
Overview
2D polygon, inheriting from std::vector<TPoint2D>.
See also:
TPolygon3D, TSegment2D, TLine2D, TPoint2D, CPolygon
#include <mrpt/math/TPolygon2D.h> class TPolygon2D: public std::vector< TPoint2D > { public: // construction TPolygon2D(); TPolygon2D(size_t N); TPolygon2D(const std::vector<TPoint2D>& v); TPolygon2D(const std::initializer_list<TPoint2D>&& vertices); TPolygon2D(const TPolygon3D& p); // methods double distance(const TPoint2D& point) const; bool contains(const TPoint2D& point) const; void getAsSegmentList(std::vector<TSegment2D>& v) const; void generate3DObject(TPolygon3D& p) const; void getCenter(TPoint2D& p) const; bool isConvex() const; void removeRepeatedVertices(); void removeRedundantVertices(); void getPlotData(std::vector<double>& x, std::vector<double>& y) const; std::tuple<std::vector<double>, std::vector<double>> getPlotData() const; mrpt::containers::yaml asYAML() const; void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const; static TPolygon2D FromYAML(const mrpt::containers::yaml& c); static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D& poly); static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D& poly, const mrpt::math::TPose2D& pose); }; // direct descendants class CPolygon;
Construction
TPolygon2D()
Default constructor
TPolygon2D(size_t N)
Constructor for a given number of vertices (uninitialized)
TPolygon2D(const std::vector<TPoint2D>& v)
Implicit constructor from a vector of 2D points.
TPolygon2D(const std::initializer_list<TPoint2D>&& vertices)
Constructor from list of vertices data, for example:
const mrpt::math::TPolygon2D p = { {-6.0, 0.5}, {8.0, 2.0}, {10.0, 4.0} };
TPolygon2D(const TPolygon3D& p)
Constructor from a 3D object.
Methods
double distance(const TPoint2D& point) const
Distance to a point (always >=0)
bool contains(const TPoint2D& point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
This works for concave or convex polygons.
void getAsSegmentList(std::vector<TSegment2D>& v) const
Gets as set of segments, instead of points.
void generate3DObject(TPolygon3D& p) const
Projects into 3D space, zeroing the z.
void getCenter(TPoint2D& p) const
Polygon’s central point.
bool isConvex() const
Checks whether is convex.
void removeRepeatedVertices()
Erase repeated vertices.
See also:
void removeRedundantVertices()
Erase every redundant vertex from the polygon, saving space.
See also:
void getPlotData(std::vector<double>& x, std::vector<double>& y) const
Gets plot data, ready to use on a 2D plot.
See also:
mrpt::gui::CDisplayWindowPlots
mrpt::containers::yaml asYAML() const
Returns a YAML representation of the polygon as a sequence (vertices) of sequences ([x y] coordinates).
User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation
(New in MRPT 2.4.1)
See also:
void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const
Get polygon bounding box.
Parameters:
On |
empty polygon |
static TPolygon2D FromYAML(const mrpt::containers::yaml& c)
Builds a polygon from a YAML sequence (vertices) of sequences ([x y] coordinates).
User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation
(New in MRPT 2.4.1)
See also:
static void createRegularPolygon( size_t numEdges, double radius, TPolygon2D& poly )
Static method to create a regular polygon, given its size and radius.
Parameters:
std::logic_error |
if radius is near zero or the number of edges is less than three. |
static void createRegularPolygon( size_t numEdges, double radius, TPolygon2D& poly, const mrpt::math::TPose2D& pose )
Static method to create a regular polygon from its size and radius.
The center will correspond to the given pose.
Parameters:
std::logic_error |
if radius is near zero or the number of edges is less than three. |