struct mrpt::math::TSegment2D

2D segment, consisting of two points.

See also:

TSegment3D, TLine2D, TPolygon2D, TPoint2D

#include <mrpt/math/TSegment2D.h>

struct TSegment2D
{
    //
fields

    TPoint2D point1;
    TPoint2D point2;

    // construction

    TSegment2D(const TPoint2D& p1, const TPoint2D& p2);
    TSegment2D();
    TSegment2D(const TSegment3D& s);

    //
methods

    double length() const;
    double distance(const TPoint2D& point) const;
    double signedDistance(const TPoint2D& point) const;
    bool contains(const TPoint2D& point) const;
    TPoint2D& operator [] (size_t i);
    constexpr const TPoint2D& operator [] (size_t i) const;
    void generate3DObject(TSegment3D& s) const;
    void getCenter(TPoint2D& p) const;
    bool operator < (const TSegment2D& s) const;
    static TSegment2D FromPoints(const TPoint2D& p1, const TPoint2D& p2);
};

Fields

TPoint2D point1

Origin point.

TPoint2D point2

Destiny point.

Construction

TSegment2D(const TPoint2D& p1, const TPoint2D& p2)

Constructor from both points.

TSegment2D()

Fast default constructor.

Initializes to (0,0)-(0,0)

TSegment2D(const TSegment3D& s)

Explicit constructor from 3D object, discarding the z.

Methods

double length() const

Segment length.

double distance(const TPoint2D& point) const

Distance to point.

double signedDistance(const TPoint2D& point) const

Distance with sign to point (sign indicates which side the point is).

bool contains(const TPoint2D& point) const

Check whether a point is inside a segment.

TPoint2D& operator [] (size_t i)

Access to points using operator[0-1].

constexpr const TPoint2D& operator [] (size_t i) const

Access to points using operator[0-1].

void generate3DObject(TSegment3D& s) const

Project into 3D space, setting the z to 0.

void getCenter(TPoint2D& p) const

Segment’s central point.

static TSegment2D FromPoints(const TPoint2D& p1, const TPoint2D& p2)

Static method, returns segment from two points.

New in MRPT 2.3.0