class mrpt::math::TPolygon3D

Overview

3D polygon, inheriting from std::vector<TPoint3D>

See also:

TPolygon2D, TSegment3D, TLine3D, TPlane, TPoint3D

#include <mrpt/math/TPolygon3D.h>

class TPolygon3D: public std::vector< TPoint3D >
{
public:
    // construction

    TPolygon3D();
    TPolygon3D(size_t N);
    TPolygon3D(const std::vector<TPoint3D>& v);
    TPolygon3D(const TPolygon2D& p);
    TPolygon3D(const std::initializer_list<TPoint3D>&& vertices);

    // methods

    mrpt::containers::yaml asYAML() const;
    double distance(const TPoint3D& point) const;
    bool contains(const TPoint3D& point) const;
    void getAsSegmentList(std::vector<TSegment3D>& v) const;
    bool getPlane(TPlane& p) const;
    void getBestFittingPlane(TPlane& p) const;
    void generate2DObject(TPolygon2D& p) const;
    void getCenter(TPoint3D& p) const;
    bool isSkew() const;
    void removeRepeatedVertices();
    void removeRedundantVertices();
    static TPolygon3D FromYAML(const mrpt::containers::yaml& c);

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

    static void createRegularPolygon(size_t numEdges, double radius, TPolygon3D& poly, const mrpt::math::TPose3D& pose);
};

Construction

TPolygon3D()

Default constructor.

Creates a polygon with no vertices.

TPolygon3D(size_t N)

Constructor for a given size.

Creates a polygon with a fixed number of vertices (uninitialized)

TPolygon3D(const std::vector<TPoint3D>& v)

Implicit constructor from a 3D points vector.

TPolygon3D(const TPolygon2D& p)

Constructor from a 2D object.

Zeroes the z.

TPolygon3D(const std::initializer_list<TPoint3D>&& vertices)

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

Parameters:

std::logic_error

if number of edges is less than three, or radius is near zero. Constructor from list of vertices data, for example:

const mrpt::math::TPolygon3D p = {
 {-6.0, 0.5, 0.0}, {8.0, 2.0, 1.0}, {10.0, 4.0, 2.0}
 };

Methods

mrpt::containers::yaml asYAML() const

Returns a YAML representation of the polygon as a sequence (vertices) of sequences ([x y z] 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:

FromYAML

double distance(const TPoint3D& point) const

Absolute distance to point.

bool contains(const TPoint3D& 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<TSegment3D>& v) const

Gets as set of segments, instead of set of points.

bool getPlane(TPlane& p) const

Gets a plane which contains the polygon.

Returns false if the polygon is skew and cannot be fit inside a plane.

void getBestFittingPlane(TPlane& p) const

Gets the best fitting plane, disregarding whether the polygon actually fits inside or not.

See also:

getBestFittingPlane

void generate2DObject(TPolygon2D& p) const

Projects into a 2D space, discarding the z.

See also:

getPlane, isSkew

void getCenter(TPoint3D& p) const

Get polygon’s central point.

bool isSkew() const

Check whether the polygon is skew.

Returns true if there doesn’t exist a plane in which the polygon can fit.

See also:

getBestFittingPlane

void removeRepeatedVertices()

Remove polygon’s repeated vertices.

void removeRedundantVertices()

Erase every redundant vertex, thus saving space.

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

Builds a polygon from a YAML sequence (vertices) of sequences ([x y z] 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:

asYAML

static void createRegularPolygon(
    size_t numEdges,
    double radius,
    TPolygon3D& poly,
    const mrpt::math::TPose3D& pose
    )

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

The center will be located on the given pose.

Parameters:

std::logic_error

if number of edges is less than three, or radius is near zero.