Ocean
Ocean::FiniteLineT2< T > Class Template Reference

This class implements an finite line in 2D space. More...

Inheritance diagram for Ocean::FiniteLineT2< T >:

Public Types

typedef T Type
 Definition of the used data type. More...
 

Public Member Functions

 FiniteLineT2 ()=default
 Creates a finite line with default parameters. More...
 
 FiniteLineT2 (const VectorT2< T > &point0, const VectorT2< T > &point1)
 Creates a finite line defined by two end points of the line. More...
 
template<typename U >
 FiniteLineT2 (const FiniteLineT2< U > &line)
 Copies a line with different data type than T. More...
 
const VectorT2< T > & point0 () const
 Returns the first end point of the line. More...
 
const VectorT2< T > & point1 () const
 Returns the second end point of the line. More...
 
const VectorT2< T > & point (const unsigned int index) const
 Returns the first or second end point of the line. More...
 
VectorT2< T > midpoint () const
 Returns the midpoint of the line. More...
 
const VectorT2< T > & direction () const
 Returns the direction of the line: normalized(point1() - point0()) More...
 
const VectorT2< T > normal () const
 Returns the normal of the line: -direction().perpendicular() The 2D cross product between the resulting normal and the direction of this line will be positive. More...
 
sqrLength () const
 Returns the squared length of the finite line. More...
 
length () const
 Returns the length of the finite line. More...
 
bool isOnLine (const VectorT2< T > &point) const
 Returns whether a given point is part of the finite line. More...
 
bool isOnInfiniteLine (const VectorT2< T > &point) const
 Returns whether a given point lies on the infinite line defined by this finite line. More...
 
bool isLeftOfLine (const VectorT2< T > &point) const
 Check if a point is in the left half-plane of the direction vector of a line A point p is located on the left side of a line, if the cross product of the direction of the line, d, and the vector pointing from starting point of the line, s, to the point p is positive: (d x (p - s)) > 0. More...
 
distance (const VectorT2< T > &point) const
 Returns the distance between the line and a given point. More...
 
sqrDistance (const VectorT2< T > &point) const
 Returns the square distance between the line and a given point. More...
 
VectorT2< T > nearestPoint (const VectorT2< T > &point) const
 Returns the point lying on this finite line nearest to an arbitrary given point. More...
 
VectorT2< T > nearestPointOnInfiniteLine (const VectorT2< T > &point, T *outOfBoundaryDistance=nullptr, T *finiteLineLocation=nullptr) const
 Returns the point on the infinite line (defined by this finite line) to an arbitrary given point. More...
 
bool intersection (const FiniteLineT2< T > &second, VectorT2< T > &point) const
 Returns the unique intersection point of two finite lines. More...
 
bool intersection (const LineT2< T > &second, VectorT2< T > &point) const
 Returns the unique intersection point of this finite line with an infinite line. More...
 
bool intersects (const FiniteLineT2< T > &second) const
 Returns whether two finite lines have a unique intersection point. More...
 
bool intersects (const LineT2< T > &second) const
 Returns whether two finite lies have an intersection. More...
 
bool isParallel (const FiniteLineT2< T > &right) const
 Returns whether two lines are parallel up to a small epsilon. More...
 
bool isCollinear (const FiniteLineT2< T > &right, const T &distanceEpsilon=NumericT< T >::weakEps(), const T &cosAngleEpsilon=NumericT< T >::cos(NumericT< T >::weakEps())) const
 Check for collinearity with other line segment. More...
 
bool isValid () const
 Returns whether this line has valid parameters. More...
 
bool isEqual (const FiniteLineT2< T > &line, const T &epsilon) const
 Returns whether two lines are equal up to a specified epsilon. More...
 
bool operator== (const FiniteLineT2< T > &right) const
 Returns whether two line are identical up to a small epsilon. More...
 
bool operator!= (const FiniteLineT2< T > &right) const
 Returns whether two line are identical up to a small epsilon. More...
 
 operator bool () const
 Returns whether this line is valid. More...
 

Protected Attributes

VectorT2< T > point0_ = VectorT2<T>(T(0), T(0))
 First end point of the line. More...
 
VectorT2< T > point1_ = VectorT2<T>(T(0), T(0))
 Second end point of the line. More...
 
VectorT2< T > direction_ = VectorT2<T>(T(0), T(0))
 Direction of the line with unit length, if the object holds valid parameters. More...
 

Detailed Description

template<typename T>
class Ocean::FiniteLineT2< T >

This class implements an finite line in 2D space.

The finite line object is invalid if both end points of the line object are identical.

Template Parameters
TData type used to represent lines
See also
FiniteLine2, FiniteLineF2, FiniteLineD2, LineT2, Line2

Member Typedef Documentation

◆ Type

template<typename T >
typedef T Ocean::FiniteLineT2< T >::Type

Definition of the used data type.

Constructor & Destructor Documentation

◆ FiniteLineT2() [1/3]

template<typename T >
Ocean::FiniteLineT2< T >::FiniteLineT2 ( )
default

Creates a finite line with default parameters.

◆ FiniteLineT2() [2/3]

template<typename T >
Ocean::FiniteLineT2< T >::FiniteLineT2 ( const VectorT2< T > &  point0,
const VectorT2< T > &  point1 
)

Creates a finite line defined by two end points of the line.

Parameters
point0First end point of the line
point1Second end point of the line, must be different from point0 to create a valid line, otherwise the line is invalid

◆ FiniteLineT2() [3/3]

template<typename T >
template<typename U >
Ocean::FiniteLineT2< T >::FiniteLineT2 ( const FiniteLineT2< U > &  line)
inlineexplicit

Copies a line with different data type than T.

Parameters
lineThe line to copy
Template Parameters
UThe data type of the second line

Member Function Documentation

◆ direction()

template<typename T >
const VectorT2< T > & Ocean::FiniteLineT2< T >::direction
inline

Returns the direction of the line: normalized(point1() - point0())

Returns
Direction vector with unit length, a zero vector if the line is invalid
See also
isValid().

◆ distance()

template<typename T >
T Ocean::FiniteLineT2< T >::distance ( const VectorT2< T > &  point) const
inline

Returns the distance between the line and a given point.

This function needs a unit vector as direction!

Parameters
pointThe point to return the distance for
Returns
Distance between point and line

◆ intersection() [1/2]

template<typename T >
bool Ocean::FiniteLineT2< T >::intersection ( const FiniteLineT2< T > &  second,
VectorT2< T > &  point 
) const
inline

Returns the unique intersection point of two finite lines.

Two aligned lines do not have one common intersection point, so that the function will return 'false' in such a case.

Parameters
secondThe second line for intersection calculation
pointResulting intersection point
Returns
True, if both lines have a common intersection point
See also
intersects().

◆ intersection() [2/2]

template<typename T >
bool Ocean::FiniteLineT2< T >::intersection ( const LineT2< T > &  second,
VectorT2< T > &  point 
) const
inline

Returns the unique intersection point of this finite line with an infinite line.

Two aligned lines do not have one common intersection point, so that the function will return 'false' in such a case.

Parameters
secondThe second line for intersection calculation
pointResulting intersection point
Returns
True, if both lines have a common intersection point
See also
intersects().

◆ intersects() [1/2]

template<typename T >
bool Ocean::FiniteLineT2< T >::intersects ( const FiniteLineT2< T > &  second) const
inline

Returns whether two finite lines have a unique intersection point.

Parameters
secondThe second line to check
Returns
True, if both lines intersect
See also
intersection().

◆ intersects() [2/2]

template<typename T >
bool Ocean::FiniteLineT2< T >::intersects ( const LineT2< T > &  second) const
inline

Returns whether two finite lies have an intersection.

Parameters
secondThe second line to check
Returns
True, if both lines intersect
See also
intersection().

◆ isCollinear()

template<typename T >
bool Ocean::FiniteLineT2< T >::isCollinear ( const FiniteLineT2< T > &  right,
const T &  distanceEpsilon = NumericT<T>::weakEps(),
const T &  cosAngleEpsilon = NumericT<T>::cos(NumericT<T>::weakEps()) 
) const
inline

Check for collinearity with other line segment.

Parameters
rightLine to check for collinearity
distanceEpsilonAcceptable distance of the endpoints of one line segment from the infinite line corresponding to the other line, default value: Numeric::weakEps()
cosAngleEpsilonCosine of the maximum angle that is allowed in order for the two segments to be considered parallel; default: cos(weakEps()), i.e., approx. one, range: [0, 1]
Returns
True if the this line and the other one are collinear, otherwise false

◆ isEqual()

template<typename T >
bool Ocean::FiniteLineT2< T >::isEqual ( const FiniteLineT2< T > &  line,
const T &  epsilon 
) const
inline

Returns whether two lines are equal up to a specified epsilon.

Two lines are equal if both lines have the same end points (while the order of the points is not important).

Parameters
lineThe second line to be used for comparison, must be valid
epsilonThe maximal distance between two equal end points, with range [0, infinity)
Returns
True, if so

◆ isLeftOfLine()

template<typename T >
bool Ocean::FiniteLineT2< T >::isLeftOfLine ( const VectorT2< T > &  point) const
inline

Check if a point is in the left half-plane of the direction vector of a line A point p is located on the left side of a line, if the cross product of the direction of the line, d, and the vector pointing from starting point of the line, s, to the point p is positive: (d x (p - s)) > 0.

It's on the line the cross product is zero and in the right half-plane it is negative.

Note
Keep in mind that if the point is not in the left half-plane, it doesn't necessarily mean that it's in the right half-plane because it could just as well be located on the line.
See also
direction()
Parameters
pointThe point to check
Returns
True, if the point is in the left half-plane

◆ isOnInfiniteLine()

template<typename T >
bool Ocean::FiniteLineT2< T >::isOnInfiniteLine ( const VectorT2< T > &  point) const
inline

Returns whether a given point lies on the infinite line defined by this finite line.

Parameters
pointThe point to check
Returns
True, if so
See also
isOnLine().

◆ isOnLine()

template<typename T >
bool Ocean::FiniteLineT2< T >::isOnLine ( const VectorT2< T > &  point) const
inline

Returns whether a given point is part of the finite line.

Parameters
pointThe point to check
Returns
True, if so
See also
isOnInfiniteLine().

◆ isParallel()

template<typename T >
bool Ocean::FiniteLineT2< T >::isParallel ( const FiniteLineT2< T > &  right) const
inline

Returns whether two lines are parallel up to a small epsilon.

Parameters
rightSecond line
Returns
True, if so

◆ isValid()

template<typename T >
bool Ocean::FiniteLineT2< T >::isValid
inline

Returns whether this line has valid parameters.

Returns
True, if so

◆ length()

template<typename T >
T Ocean::FiniteLineT2< T >::length
inline

Returns the length of the finite line.

Returns
Distance between the end points of the line

◆ midpoint()

template<typename T >
VectorT2< T > Ocean::FiniteLineT2< T >::midpoint
inline

Returns the midpoint of the line.

Returns
Midpoint point of the line

◆ nearestPoint()

template<typename T >
VectorT2< T > Ocean::FiniteLineT2< T >::nearestPoint ( const VectorT2< T > &  point) const

Returns the point lying on this finite line nearest to an arbitrary given point.

This function needs a unit vector as direction!

Parameters
pointArbitrary point outside the line
Returns
Nearest point on the finite line
See also
nearestPointOnInfiniteLine().

◆ nearestPointOnInfiniteLine()

template<typename T >
VectorT2< T > Ocean::FiniteLineT2< T >::nearestPointOnInfiniteLine ( const VectorT2< T > &  point,
T *  outOfBoundaryDistance = nullptr,
T *  finiteLineLocation = nullptr 
) const

Returns the point on the infinite line (defined by this finite line) to an arbitrary given point.

In addition to providing the projected point on the infinite line, this function can return the distance to the closest end point of the finite line when lying outside of the finite line's boundaries. A negative distance indicates a projected point close to point0(), a positive distance indicates a projected point close to point1(). This function needs a unit vector as direction!

Parameters
pointArbitrary point outside the line
outOfBoundaryDistanceOptional resulting distance between the projected point on the infinite line and the closest end point of the finite line, with range (-infinity, infinity)
finiteLineLocationOptional resulting location of the projected point in relation to the finite line so that the following holds point() + direction() * finiteLineLocation, with range (-infinity, infinity)
Returns
Nearest point on the infinite line
See also
nearestPoint().

◆ normal()

template<typename T >
const VectorT2< T > Ocean::FiniteLineT2< T >::normal
inline

Returns the normal of the line: -direction().perpendicular() The 2D cross product between the resulting normal and the direction of this line will be positive.

Returns
Normal vector with unit length
See also
isValid().

◆ operator bool()

template<typename T >
Ocean::FiniteLineT2< T >::operator bool
inlineexplicit

Returns whether this line is valid.

Returns
True, if so

◆ operator!=()

template<typename T >
bool Ocean::FiniteLineT2< T >::operator!= ( const FiniteLineT2< T > &  right) const
inline

Returns whether two line are identical up to a small epsilon.

Parameters
rightThe right line
Returns
True, if so

◆ operator==()

template<typename T >
bool Ocean::FiniteLineT2< T >::operator== ( const FiniteLineT2< T > &  right) const
inline

Returns whether two line are identical up to a small epsilon.

Two finite lines are identical if both lines have the same endpoint (independent of the order of the end points).

Parameters
rightThe right line
Returns
True, if so
See also
isEqual().

◆ point()

template<typename T >
const VectorT2< T > & Ocean::FiniteLineT2< T >::point ( const unsigned int  index) const
inline

Returns the first or second end point of the line.

Parameters
indexThe index of the point to be returned, with range [0, 1]
Returns
First or second end point of the line

◆ point0()

template<typename T >
const VectorT2< T > & Ocean::FiniteLineT2< T >::point0
inline

Returns the first end point of the line.

Returns
First end point of the line

◆ point1()

template<typename T >
const VectorT2< T > & Ocean::FiniteLineT2< T >::point1
inline

Returns the second end point of the line.

Returns
Second end point of the line

◆ sqrDistance()

template<typename T >
T Ocean::FiniteLineT2< T >::sqrDistance ( const VectorT2< T > &  point) const
inline

Returns the square distance between the line and a given point.

Parameters
pointThe point to return the distance for
Returns
The resulting square distance between point and line, with range [0, infinity)

◆ sqrLength()

template<typename T >
T Ocean::FiniteLineT2< T >::sqrLength
inline

Returns the squared length of the finite line.

Returns
Squared distance between the end points of the line

Field Documentation

◆ direction_

template<typename T >
VectorT2<T> Ocean::FiniteLineT2< T >::direction_ = VectorT2<T>(T(0), T(0))
protected

Direction of the line with unit length, if the object holds valid parameters.

◆ point0_

template<typename T >
VectorT2<T> Ocean::FiniteLineT2< T >::point0_ = VectorT2<T>(T(0), T(0))
protected

First end point of the line.

◆ point1_

template<typename T >
VectorT2<T> Ocean::FiniteLineT2< T >::point1_ = VectorT2<T>(T(0), T(0))
protected

Second end point of the line.


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