Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
GIMLI::Line Class Reference

A line. More...

#include <line.h>

+ Collaboration diagram for GIMLI::Line:

Public Member Functions

 Line ()
 
 Line (const RVector3 &p0)
 
 Line (const RVector3 &p0, const RVector3 &p1)
 
 Line (const Line &line)
 
 ~Line ()
 
Lineoperator= (const Line &line)
 
const RVector3 operator() (double t) const
 
bool operator== (const Line &line) const
 
bool operator!= (const Line &line) const
 
bool checkValidity (double tol=TOLERANCE)
 
bool valid () const
 
bool compare (const Line &line, double tol=TOLERANCE) const
 
const RVector3p0 () const
 
const RVector3p1 () const
 
bool intersectRay (const RVector3 &start, const RVector3 &dir, RVector3 &pos, double tol=TOLERANCE) const
 
RVector3 intersect (const RVector3 &start, const RVector3 &dir, double tol=TOLERANCE) const
 
RVector3 intersect (const Line &line, double tol=TOLERANCE) const
 
double nearest (const RVector3 &p) const
 
RVector3 at (double t) const
 
double distance (const RVector3 &pos) const
 
double t (const RVector3 &pos, double tol=TOLERANCE) const
 
bool touch1 (const RVector3 &pos, int &pFunIdx, double tol=TOLERANCE) const
 
bool touch (const RVector3 &pos, double tol=TOLERANCE) const
 
double length () const
 

Protected Member Functions

void copy_ (const Line &line)
 

Protected Attributes

RVector3 _p0
 
RVector3 _p1
 
bool valid_
 

Detailed Description

A line.

A straight line segment in the geometrically point of view.

Constructor & Destructor Documentation

◆ Line() [1/4]

GIMLI::Line::Line ( )

Default constructor. Constructs an invalid straight line.

Referenced by compare(), copy_(), intersect(), Line(), operator!=(), operator=(), and operator==().

◆ Line() [2/4]

GIMLI::Line::Line ( const RVector3 & p0)

Constructor, construct a line between p0 and the orign [0.0, 0.0, 0.0 ].

References checkValidity().

◆ Line() [3/4]

GIMLI::Line::Line ( const RVector3 & p0,
const RVector3 & p1 )

Constructor construct a line betweem p0, and p1.

References checkValidity(), p0(), and p1().

◆ Line() [4/4]

GIMLI::Line::Line ( const Line & line)

Copycontructor

References copy_(), and Line().

◆ ~Line()

GIMLI::Line::~Line ( )

Default destructor. Destroys the object.

Member Function Documentation

◆ at()

RVector3 GIMLI::Line::at ( double t) const
inline

Apply the line as function. ret = _p0 + (_p1 - _p0) * t

References t().

Referenced by intersectRay(), and operator()().

◆ checkValidity()

bool GIMLI::Line::checkValidity ( double tol = TOLERANCE)

Check validility of the straight line. False if [ p0-p1] < tol.

Referenced by Line(), and Line().

◆ compare()

bool GIMLI::Line::compare ( const Line & line,
double tol = TOLERANCE ) const

Compare two lines with a given tolerance. Check if both ref points from line touch this line.. distance(this, line.p1)< tol && distance(this, line.p2)< tol

References Line(), p0(), p1(), and touch().

Referenced by operator==().

◆ copy_()

void GIMLI::Line::copy_ ( const Line & line)
protected

internal: copy content of line into this line

References Line(), p0(), p1(), and valid().

Referenced by Line(), and operator=().

◆ distance()

double GIMLI::Line::distance ( const RVector3 & pos) const

Return the distance between this line and pos, https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html; | x2-x1 cross x1-x0 | / | x2 -x1 |

Referenced by touch(), and touch1().

◆ intersect() [1/2]

RVector3 GIMLI::Line::intersect ( const Line & line,
double tol = TOLERANCE ) const

Returns the intersection point between line and this line. Returns an invalid RVector3 of both do not touch, are equal or parallel. Return is invalid if they don't intersect.

References Line().

◆ intersect() [2/2]

RVector3 GIMLI::Line::intersect ( const RVector3 & start,
const RVector3 & dir,
double tol = TOLERANCE ) const

Return insection position of this line segment with a the ray given by start and direction dir. Pos is invalid for no intersection.

References intersectRay().

◆ intersectRay()

bool GIMLI::Line::intersectRay ( const RVector3 & start,
const RVector3 & dir,
RVector3 & pos,
double tol = TOLERANCE ) const

Return true if this line segment intersect with a the ray given by start and direction dir. Fill pos with the intersection position. Returns also true if the ray is parallel and the distance between Line and ray is smaller than the tolerance but pos is not valid.

References at(), and GIMLI::Pos::length().

Referenced by intersect(), GIMLI::EdgeShape::intersectRay(), and GIMLI::Shape::touch().

◆ length()

double GIMLI::Line::length ( ) const
inline

Return the length if the line.

Referenced by touch1().

◆ nearest()

double GIMLI::Line::nearest ( const RVector3 & p) const

Returns line parameter t that represents the nearest position to the line for the given point p. Feed it to at() and you get the nearest point.

◆ operator!=()

bool GIMLI::Line::operator!= ( const Line & line) const
inline

Not_equal_to operator

References Line().

◆ operator()()

const RVector3 GIMLI::Line::operator() ( double t) const
inline

Functor to the line function. ret = _p0 + (_p1 - _p0) * t;

References at(), and t().

◆ operator=()

Line & GIMLI::Line::operator= ( const Line & line)

Assignment operator

References copy_(), and Line().

◆ operator==()

bool GIMLI::Line::operator== ( const Line & line) const
inline

Equal_to operator

References compare(), and Line().

◆ p0()

const RVector3 & GIMLI::Line::p0 ( ) const
inline

Return const reference to ref. point p0

Referenced by compare(), copy_(), GIMLI::Plane::intersect(), and Line().

◆ p1()

const RVector3 & GIMLI::Line::p1 ( ) const
inline

Return const reference to ref. point p1

Referenced by compare(), copy_(), GIMLI::Plane::intersect(), and Line().

◆ t()

double GIMLI::Line::t ( const RVector3 & pos,
double tol = TOLERANCE ) const

Return position at line. solves: pos = _p0 + (_p1 - _p0) * ret. ret = (pos - _p0) / (_p1 - _p0) Throws an exception if pos is not on Line.

References t().

Referenced by at(), operator()(), t(), GIMLI::Shape::touch(), and touch1().

◆ touch()

bool GIMLI::Line::touch ( const RVector3 & pos,
double tol = TOLERANCE ) const

Return true if pos touches the line.

References distance().

Referenced by compare(), and GIMLI::EdgeShape::touch().

◆ touch1()

bool GIMLI::Line::touch1 ( const RVector3 & pos,
int & pFunIdx,
double tol = TOLERANCE ) const

Return true if pos touches the line. pFunIdx gives an identifier which shows the dependency between this Line and the RVector3 pos. Possible return values are:
-1 – this straight line don't touch the Position pos
1 – this straight line touch the Position pos and pos lies before _p0
2 – this straight line touch the Position pos and pos lies at the same position like pos _p0
3 – this straight line touch the Position pos and pos lies within the definition positions _p0 and _p1
4 – this straight line touch the Position pos and pos lies at the same position like pos _p1
5 – this straight line touch the Position pos and pos lies behind _p1

References distance(), length(), and t().

Referenced by GIMLI::Mesh::createNodeWithCheck(), and GIMLI::PolygonFace::insertNode().

◆ valid()

bool GIMLI::Line::valid ( ) const
inline

Return the validity of this line.

Referenced by copy_(), and GIMLI::Plane::intersect().