class mrpt::math::CPolygon

A wrapper of a TPolygon2D class, implementing CSerializable.

#include <mrpt/math/CPolygon.h>

class CPolygon:
    public mrpt::serialization::CSerializable,
    public mrpt::math::TPolygon2D
{
public:
    //
fields

    T elements;

    //
methods

    void AddVertex(double x, double y);
    double GetVertex_x(size_t i) const;
    double GetVertex_y(size_t i) const;
    size_t verticesCount() const;
    void setAllVertices(const std::vector<double>& x, const std::vector<double>& y);
    void setAllVertices(size_t nVertices, const double* xs, const double* ys);
    void setAllVertices(size_t nVertices, const float* xs, const float* ys);
    void getAllVertices(std::vector<double>& x, std::vector<double>& y) const;
    void Clear();
    bool PointIntoPolygon(double x, double y) const;
    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;
    void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const;
    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);
};

Fields

T elements

STL member.

Methods

void AddVertex(double x, double y)

Add a new vertex to polygon.

double GetVertex_x(size_t i) const

Methods for accessing the vertices.

See also:

verticesCount

size_t verticesCount() const

Returns the vertices count in the polygon:

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

Set all vertices at once.

void setAllVertices(size_t nVertices, const double* xs, const double* ys)

Set all vertices at once.

Please use the std::vector version whenever possible unless efficiency is really an issue

void setAllVertices(size_t nVertices, const float* xs, const float* ys)

Set all vertices at once.

Please use the std::vector version whenever possible unless efficiency is really an issue

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

Get all vertices at once.

void Clear()

Clear the polygon, erasing all vertices.

bool PointIntoPolygon(double x, double y) const

Check if a point is inside the polygon.

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:

removeRedundantVertices

void removeRedundantVertices()

Erase every redundant vertex from the polygon, saving space.

See also:

removeRepeatedVertices

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

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

Get polygon bounding box.

Parameters:

On

empty polygon

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.