struct mrpt::math::TLine3D

3D line, represented by a base point and a director vector.

See also:

TLine2D, TSegment3D, TPlane, TPolygon3D, TPoint3D

#include <mrpt/math/TLine3D.h>

struct TLine3D
{
    //
fields

    TPoint3D pBase;
    TVector3D director {.0, .0, .0};

    // construction

    TLine3D();
    TLine3D(const TPoint3D& p1, const TPoint3D& p2);
    TLine3D(const TSegment3D& s);
    TLine3D(const TLine2D& l);

    //
methods

    bool contains(const TPoint3D& point) const;
    double distance(const TPoint3D& point) const;
    TPoint3D closestPointTo(const TPoint3D& p) const;

    std::optional<double> distance(
        const TLine3D& point,
        const mrpt::optional_ref<mrpt::math::TPoint3D>& outMidPoint = std::nullopt
        ) const;

    void unitarize();
    void getDirectorVector(double(&) vector [3]) const;
    const TVector3D& getDirectorVector() const;
    void getUnitaryDirectorVector(double(&) vector [3]);
    void generate2DObject(TLine2D& l) const;
    std::string asString() const;
    static TLine3D FromPointAndDirector(const TPoint3D& basePoint, const TVector3D& directorVector);
    static TLine3D FromTwoPoints(const TPoint3D& p1, const TPoint3D& p2);
};

Fields

TPoint3D pBase

Base point.

TVector3D director {.0, .0, .0}

Director vector.

Construction

TLine3D()

Fast default constructor.

Initializes to all zeros.

TLine3D(const TPoint3D& p1, const TPoint3D& p2)

Constructor from two points, through which the line will pass.

Parameters:

std::logic_error

if both points are the same.

See also:

mrpt::math::getRegressionLine()

TLine3D(const TSegment3D& s)

Constructor from 3D segment

TLine3D(const TLine2D& l)

Constructor from 2D object.

Zeroes the z.

Methods

bool contains(const TPoint3D& point) const

Check whether a point is inside the line.

double distance(const TPoint3D& point) const

Absolute distance between the line and a point.

TPoint3D closestPointTo(const TPoint3D& p) const

Closest point to p along the line.

It is computed as the intersection of this with the plane perpendicular to this that passes through p [New in MRPT 2.3.1]

std::optional<double> distance(
    const TLine3D& point,
    const mrpt::optional_ref<mrpt::math::TPoint3D>& outMidPoint = std::nullopt
    ) const

Minimum distance between this and another line.

The return will be std::nullopt if lines are parallel, or zero if they intersect, a positive number otherwise. New in MRPT 2.3.0

void unitarize()

Unitarize director vector.

void getDirectorVector(double(&) vector [3]) const

Get director vector.

const TVector3D& getDirectorVector() const

Get director vector (may be NOT unitary if not set so by the user)

See also:

getUnitaryDirectorVector(), unitarize()

void getUnitaryDirectorVector(double(&) vector [3])

Unitarize and then get director vector.

void generate2DObject(TLine2D& l) const

Project into 2D space, discarding the Z coordinate.

Parameters:

std::logic_error

if the line’s director vector is orthogonal to the XY plane.

std::string asString() const

Returns “P=[x,y,z] u=[ux,uy,uz]”.

[New in MRPT 2.1.0]

static TLine3D FromPointAndDirector(const TPoint3D& basePoint, const TVector3D& directorVector)

Static constructor from a point and a director vector.

[New in MRPT 2.0.4]

static TLine3D FromTwoPoints(const TPoint3D& p1, const TPoint3D& p2)

Static constructor from two points.

[New in MRPT 2.0.4]

See also:

mrpt::math::getRegressionLine()