Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::core::line2d< T > Class Template Reference

2D line between two points with intersection methods. More...

#include <nirtcpp/core/engine/line2d.hpp>

Public Member Functions

 line2d ()
 Default constructor for line going from (0,0) to (1,1).
 
 line2d (T xa, T ya, T xb, T yb)
 Constructor for line between the two points.
 
 line2d (const vector2d< T > &start, const vector2d< T > &end)
 Constructor for line between the two points given as vectors.
 
line2d< Toperator+ (const vector2d< T > &point) const
 
line2d< T > & operator+= (const vector2d< T > &point)
 
line2d< Toperator- (const vector2d< T > &point) const
 
line2d< T > & operator-= (const vector2d< T > &point)
 
bool operator== (const line2d< T > &other) const
 
bool operator!= (const line2d< T > &other) const
 
void setLine (const T &xa, const T &ya, const T &xb, const T &yb)
 Set this line to new line going through the two points.
 
void setLine (const vector2d< T > &nstart, const vector2d< T > &nend)
 Set this line to new line going through the two points.
 
void setLine (const line2d< T > &line)
 Set this line to new line given as parameter.
 
T getLength () const
 Get length of line.
 
T getLengthSQ () const
 Get squared length of the line.
 
vector2d< TgetMiddle () const
 Get middle of the line.
 
vector2d< TgetVector () const
 Get the vector of the line.
 
bool intersectAsSegments (const line2d< T > &other) const
 
bool incidentSegments (const line2d< T > &other) const
 
bool nearlyParallel (const line2d< T > &line, const T factor=relativeErrorFactor< T >()) const
 
vector2d< TfastLinesIntersection (const line2d< T > &l) const
 
bool lineIntersectSegment (const line2d< T > &segment, vector2d< T > &out) const
 
bool intersectWith (const line2d< T > &l, vector2d< T > &out, bool checkOnlySegments=true, bool ignoreCoincidentLines=false) const
 Tests if this line intersects with another line.
 
vector2d< TgetUnitVector () const
 Get unit vector of the line.
 
f64 getAngleWith (const line2d< T > &l) const
 Get angle between this line and given line.
 
T getPointOrientation (const vector2d< T > &point) const
 Tells us if the given point lies to the left, right, or on the line.
 
bool isPointOnLine (const vector2d< T > &point) const
 Check if the given point is a member of the line.
 
bool isPointBetweenStartAndEnd (const vector2d< T > &point) const
 Check if the given point is between start and end of the line.
 
vector2d< TgetClosestPoint (const vector2d< T > &point, bool checkOnlySegments=true) const
 Get the closest point on this line to a point.
 
vector2df getClosestPoint (const vector2df &point, bool checkOnlySegments) const
 

Public Attributes

vector2d< Tstart
 Start point of the line.
 
vector2d< Tend
 End point of the line.
 

Detailed Description

template<class T>
class nirt::core::line2d< T >

2D line between two points with intersection methods.

Member Function Documentation

◆ fastLinesIntersection()

template<class T >
vector2d< T > nirt::core::line2d< T >::fastLinesIntersection ( const line2d< T > &  l) const
inline

returns a intersection point of 2 lines (if lines are not parallel). Behaviour undefined if lines are parallel or coincident. It's on optimized intersectWith with checkOnlySegments=false and ignoreCoincidentLines=true

◆ getAngleWith()

template<class T >
f64 nirt::core::line2d< T >::getAngleWith ( const line2d< T > &  l) const
inline

Get angle between this line and given line.

Parameters
lOther line for test.
Returns
Angle in degrees.

◆ getClosestPoint()

template<class T >
vector2d< T > nirt::core::line2d< T >::getClosestPoint ( const vector2d< T > &  point,
bool  checkOnlySegments = true 
) const
inline

Get the closest point on this line to a point.

Parameters
pointStarting search at this point
checkOnlySegmentsDefault (true) is to return a point on the line-segment (between begin and end) of the line. When set to false the function will check for the first the closest point on the the line even when outside the segment.

◆ getLength()

template<class T >
T nirt::core::line2d< T >::getLength ( ) const
inline

Get length of line.

Returns
Length of the line.

◆ getLengthSQ()

template<class T >
T nirt::core::line2d< T >::getLengthSQ ( ) const
inline

Get squared length of the line.

Returns
Squared length of line.

◆ getMiddle()

template<class T >
vector2d< T > nirt::core::line2d< T >::getMiddle ( ) const
inline

Get middle of the line.

Returns
center of the line.

◆ getPointOrientation()

template<class T >
T nirt::core::line2d< T >::getPointOrientation ( const vector2d< T > &  point) const
inline

Tells us if the given point lies to the left, right, or on the line.

Returns
0 if the point is on the line <0 if to the left, or >0 if to the right.

◆ getUnitVector()

template<class T >
vector2d< T > nirt::core::line2d< T >::getUnitVector ( ) const
inline

Get unit vector of the line.

Returns
Unit vector of this line.

◆ getVector()

template<class T >
vector2d< T > nirt::core::line2d< T >::getVector ( ) const
inline

Get the vector of the line.

Returns
The vector of the line.

◆ incidentSegments()

template<class T >
bool nirt::core::line2d< T >::incidentSegments ( const line2d< T > &  other) const
inline

Check if 2 segments are incident (intersects in exactly 1 point).

◆ intersectAsSegments()

template<class T >
bool nirt::core::line2d< T >::intersectAsSegments ( const line2d< T > &  other) const
inline

Check if this segment intersects another segment, or if segments are coincindent (colinear).

◆ intersectWith()

template<class T >
bool nirt::core::line2d< T >::intersectWith ( const line2d< T > &  l,
vector2d< T > &  out,
bool  checkOnlySegments = true,
bool  ignoreCoincidentLines = false 
) const
inline

Tests if this line intersects with another line.

Parameters
lOther line to test intersection with.
checkOnlySegmentsDefault is to check intersection between the begin and endpoints. When set to false the function will check for the first intersection point when extending the lines.
outIf there is an intersection, the location of the intersection will be stored in this vector.
ignoreCoincidentLinesWhen true coincident lines (lines above each other) are never considered as intersecting. When false the center of the overlapping part is returned.
Returns
True if there is an intersection, false if not.

◆ isPointBetweenStartAndEnd()

template<class T >
bool nirt::core::line2d< T >::isPointBetweenStartAndEnd ( const vector2d< T > &  point) const
inline

Check if the given point is between start and end of the line.

Assumes that the point is already somewhere on the line.

◆ isPointOnLine()

template<class T >
bool nirt::core::line2d< T >::isPointOnLine ( const vector2d< T > &  point) const
inline

Check if the given point is a member of the line.

Returns
True if point is between start and end, else false.

◆ lineIntersectSegment()

template<class T >
bool nirt::core::line2d< T >::lineIntersectSegment ( const line2d< T > &  segment,
vector2d< T > &  out 
) const
inline

Check if this line intersect a segment. The eventual intersection point is returned in "out".

◆ nearlyParallel()

template<class T >
bool nirt::core::line2d< T >::nearlyParallel ( const line2d< T > &  line,
const T  factor = relativeErrorFactor<T>() 
) const
inline

Check if 2 lines/segments are parallel or nearly parallel.


The documentation for this class was generated from the following file:

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print