8#ifndef META_OCEAN_MATH_FINITE_LINE_2_H
9#define META_OCEAN_MATH_FINITE_LINE_2_H
109 template <
typename U>
315 explicit inline operator bool()
const;
362 ocean_assert(index <= 1u);
456 const T dotProduct = lineOffset * pointOffset;
465 if (dotProduct >= lineOffset.
sqr())
482 const T dotProduct = lineOffset * pointOffset;
488 if (outOfBoundaryDistance)
492 *outOfBoundaryDistance = std::min(pointOffset *
direction_, T(0));
493 ocean_assert(*outOfBoundaryDistance <= T(0));
496 else if (dotProduct >= lineOffset.
sqr())
500 if (outOfBoundaryDistance)
504 *outOfBoundaryDistance = std::max(T(0), pointOffset *
direction_ -
length());
505 ocean_assert(*outOfBoundaryDistance >= T(0));
512 if (outOfBoundaryDistance)
514 *outOfBoundaryDistance = T(0);
520 if (finiteLineLocation)
525 *finiteLineLocation =
length;
610 const T squareDistanceEpsilon = distanceEpsilon * distanceEpsilon;
616 const bool validNormalOrientations =
NumericT<T>::abs(cosAngle) >= cosAngleEpsilon;
618 return validDistanceRightToThis && validDistanceThisToRight && validNormalOrientations;
648 return !(*
this == right);
This class implements an finite line in 2D space.
Definition FiniteLine2.h:82
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 ...
Definition FiniteLine2.h:425
const VectorT2< T > & point(const unsigned int index) const
Returns the first or second end point of the line.
Definition FiniteLine2.h:360
FiniteLineT2(const FiniteLineT2< U > &line)
Copies a line with different data type than T.
Definition FiniteLine2.h:340
bool isValid() const
Returns whether this line has valid parameters.
Definition FiniteLine2.h:622
bool isEqual(const FiniteLineT2< T > &line, const T &epsilon) const
Returns whether two lines are equal up to a specified epsilon.
Definition FiniteLine2.h:628
VectorT2< Scalar > direction_
Definition FiniteLine2.h:326
bool intersects(const LineT2< T > &second) const
Returns whether two finite lies have an intersection.
Definition FiniteLine2.h:587
bool intersection(const FiniteLineT2< T > &second, VectorT2< T > &point) const
Returns the unique intersection point of two finite lines.
Definition FiniteLine2.h:533
FiniteLineT2()=default
Creates a finite line with default parameters.
T length() const
Returns the length of the finite line.
Definition FiniteLine2.h:403
bool operator!=(const FiniteLineT2< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition FiniteLine2.h:646
VectorT2< Scalar > point1_
Definition FiniteLine2.h:323
bool isOnLine(const VectorT2< T > &point) const
Returns whether a given point is part of the finite line.
Definition FiniteLine2.h:409
bool isOnInfiniteLine(const VectorT2< T > &point) const
Returns whether a given point lies on the infinite line defined by this finite line.
Definition FiniteLine2.h:417
bool isParallel(const FiniteLineT2< T > &right) const
Returns whether two lines are parallel up to a small epsilon.
Definition FiniteLine2.h:596
const VectorT2< T > & direction() const
Returns the direction of the line: normalized(point1() - point0()).
Definition FiniteLine2.h:381
FiniteLineT2(const VectorT2< T > &point0, const VectorT2< T > &point1)
Creates a finite line defined by two end points of the line.
Definition FiniteLine2.h:330
bool intersects(const FiniteLineT2< T > &second) const
Returns whether two finite lines have a unique intersection point.
Definition FiniteLine2.h:578
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.
Definition FiniteLine2.h:604
T distance(const VectorT2< T > &point) const
Returns the distance between the line and a given point.
Definition FiniteLine2.h:433
const VectorT2< Scalar > & point0() const
bool operator==(const FiniteLineT2< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition FiniteLine2.h:639
T sqrDistance(const VectorT2< T > &point) const
Returns the square distance between the line and a given point.
Definition FiniteLine2.h:441
Scalar Type
Definition FiniteLine2.h:88
const VectorT2< T > normal() const
Returns the normal of the line: -direction().perpendicular() The 2D cross product between the resulti...
Definition FiniteLine2.h:387
VectorT2< T > nearestPoint(const VectorT2< T > &point) const
Returns the point lying on this finite line nearest to an arbitrary given point.
Definition FiniteLine2.h:449
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.
Definition FiniteLine2.h:475
VectorT2< Scalar > point0_
Definition FiniteLine2.h:320
const VectorT2< Scalar > & point1() const
bool intersection(const LineT2< T > &second, VectorT2< T > &point) const
Returns the unique intersection point of this finite line with an infinite line.
Definition FiniteLine2.h:556
VectorT2< T > midpoint() const
Returns the midpoint of the line.
Definition FiniteLine2.h:375
T sqrLength() const
Returns the squared length of the finite line.
Definition FiniteLine2.h:397
This class implements an infinite line in 2D space.
Definition Line2.h:83
bool isValid() const
Returns whether this line has valid parameters.
Definition Line2.h:405
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 ...
Definition Line2.h:455
static constexpr T weakEps()
Returns a weak epsilon.
static constexpr bool isInsideRange(const T lower, const T value, const T upper, const T epsilon=NumericT< T >::eps())
Returns whether a value lies between a given range up to a provided epsilon border.
Definition Numeric.h:2881
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1537
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1499
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1588
This class implements a vector with two elements.
Definition Vector2.h:96
T sqr() const
Returns the square of the vector length.
Definition Vector2.h:626
T length() const
Returns the length of the vector.
Definition Vector2.h:620
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition Vector2.h:549
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition base/Utilities.h:1159
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition base/Utilities.h:1099
FiniteLineT2< double > FiniteLineD2
Instantiation of the LineT2 template class using a double precision float data type.
Definition FiniteLine2.h:35
std::vector< FiniteLineT2< T > > FiniteLinesT2
Definition of a typename alias for vectors with FiniteLineT2 objects.
Definition FiniteLine2.h:50
FiniteLineT2< Scalar > FiniteLine2
Definition of the FiniteLine2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with si...
Definition FiniteLine2.h:28
FiniteLineT2< float > FiniteLineF2
Instantiation of the LineT2 template class using a single precision float data type.
Definition FiniteLine2.h:42
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition FiniteLine2.h:57
std::vector< FiniteLineD2 > FiniteLinesD2
Definition of a vector holding FiniteLineD2 objects.
Definition FiniteLine2.h:64
std::vector< FiniteLineF2 > FiniteLinesF2
Definition of a vector holding FiniteLineF2 objects.
Definition FiniteLine2.h:71
The namespace covering the entire Ocean framework.
Definition Accessor.h:15