Class TPolygon2D

Inheritance Relationships

Base Type

  • public std::vector< TPoint2D >

Derived Type

Class Documentation

class TPolygon2D : public std::vector<TPoint2D>

2D polygon, inheriting from std::vector<TPoint2D>.

Subclassed by mrpt::math::CPolygon

Public Functions

inline TPolygon2D()

Default constructor

inline explicit TPolygon2D(size_t N)

Constructor for a given number of vertices (uninitialized)

inline TPolygon2D(const std::vector<TPoint2D> &v)

Implicit constructor from a vector of 2D points

inline 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}
 };

explicit TPolygon2D(const TPolygon3D &p)

Constructor from a 3D object.

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.

void removeRedundantVertices()

Erase every redundant vertex from the polygon, saving space.

void getPlotData(std::vector<double> &x, std::vector<double> &y) const

Gets plot data, ready to use on a 2D plot.

inline std::tuple<std::vector<double>, std::vector<double>> getPlotData() const
mrpt::containers::yaml asYAML() const

Returns a YAML representation of the polygon as a sequence (vertices) of sequences ([x y] coordinates).

See also

FromYAML

Note

User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation

Note

(New in MRPT 2.4.1)

void getBoundingBox(TPoint2D &min_coords, TPoint2D &max_coords) const

Get polygon bounding box.

Throws:

On – empty polygon

Public Static Functions

static TPolygon2D FromYAML(const mrpt::containers::yaml &c)

Builds a polygon from a YAML sequence (vertices) of sequences ([x y] coordinates).

See also

asYAML

Note

User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation

Note

(New in MRPT 2.4.1)

static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D &poly)

Static method to create a regular polygon, given its size and radius.

Throws:

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.

Throws:

std::logic_error – if radius is near zero or the number of edges is less than three.