8 #ifndef META_OCEAN_MATH_LINE_2_H
9 #define META_OCEAN_MATH_LINE_2_H
21 template <
typename T>
class LineT2;
84 template <
typename U>
friend class LineT2;
129 template <
typename U>
264 explicit inline operator bool()
const;
284 template <
typename T>
286 linePoint(T(0), T(0)),
287 lineDirection(T(0), T(0))
292 template <
typename T>
295 lineDirection(direction)
300 template <
typename T>
309 linePoint = normal * -parameters.
z();
310 ocean_assert(isValid());
313 template <
typename T>
322 linePoint = normal * -distance;
323 ocean_assert(isValid());
326 template <
typename T>
327 template <
typename U>
334 template <
typename T>
340 template <
typename T>
343 ocean_assert(isValid());
344 return linePoint + lineDirection * distance;
347 template <
typename T>
350 return lineDirection;
353 template <
typename T>
356 ocean_assert(isValid());
357 VectorT2<T> result(-lineDirection.perpendicular());
365 template <
typename T>
368 ocean_assert(isValid());
373 distance = -normalVector * linePoint;
382 template <
typename T>
385 ocean_assert(isValid());
388 const T distance = -normalVector * linePoint;
396 if (forcePositiveDistance && distance < T(0))
398 return VectorT3<T>(-normalVector.
x(), -normalVector.
y(), -distance);
401 return VectorT3<T>(normalVector.
x(), normalVector.
y(), distance);
404 template <
typename T>
407 return !lineDirection.isNull();
410 template <
typename T>
416 template <
typename T>
419 return !(*
this == right);
422 template <
typename T>
428 template <
typename T>
431 ocean_assert(hasUnitDirection());
432 ocean_assert(isValid());
435 const T length = offset.
length();
443 if (!std::is_same<T, float>::value)
454 template <
typename T>
457 ocean_assert(isValid());
465 ocean_assert(hasUnitDirection());
466 ocean_assert(isValid());
469 const float length = offset.
length();
485 template <
typename T>
488 ocean_assert(hasUnitDirection());
489 ocean_assert(isValid());
491 const VectorT2<T> pointOnLine(nearestPoint(point));
492 ocean_assert((!std::is_same<T, double>::value) || isOnLine(pointOnLine));
494 return (pointOnLine - point).length();
497 template <
typename T>
500 ocean_assert(hasUnitDirection());
501 ocean_assert(isValid());
503 const VectorT2<T> pointOnLine(nearestPoint(point));
505 return (pointOnLine - point).sqr();
508 template <
typename T>
511 ocean_assert(hasUnitDirection());
512 ocean_assert(isValid());
516 return linePoint + lineDirection * (lineDirection * offset);
519 template <
typename T>
522 ocean_assert(hasUnitDirection());
524 if (isParallel(right))
533 const T normalLength = normal.
length();
542 const T cosValue = right.
lineDirection * (normal / normalLength);
550 const T offset = normalLength / cosValue;
554 if constexpr (std::is_same<T, double>::value)
556 ocean_assert_accuracy(right.
isOnLine(point));
557 ocean_assert_accuracy(isOnLine(point));
563 template <
typename T>
566 ocean_assert(hasUnitDirection());
567 ocean_assert(isValid() && right.
isValid());
572 template <
typename T>
575 ocean_assert(isValid() && right.
isValid());
576 return isParallel(right) && isOnLine(right.
point());
579 template <
typename T>
582 static_assert(std::is_same<float, T>::value || std::is_same<double, T>::value,
"Type T can be either float or double.");
583 ocean_assert(points && size >= 2);
596 for (
size_t i = 0; i < size; i++)
606 xy += point[0] * point[1];
609 ocean_assert(size != 0);
610 const T invSize = T(1) / T(size);
618 const T xSqr = x * x;
619 const T ySqr = y * y;
621 const T nominator = 2 * (xy - x * y);
622 const T denominator = (x2 - xSqr) - (y2 - ySqr);
This class implements an infinite line in 2D space.
Definition: Line2.h:83
const VectorT2< T > & point() const
Returns a point on the line.
Definition: Line2.h:335
bool hasUnitDirection() const
Returns whether this line has a unit vector as direction.
Definition: Line2.h:411
bool intersection(const LineT2< T > &right, VectorT2< T > &point) const
Returns the unique intersection point of two lines.
Definition: Line2.h:520
bool isParallel(const LineT2< T > &right) const
Returns whether two lines are parallel up to a small epsilon.
Definition: Line2.h:564
bool operator==(const LineT2< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition: Line2.h:573
VectorT2< T > normal() const
Returns a normal to the direction of this line.
Definition: Line2.h:354
bool isValid() const
Returns whether this line has valid parameters.
Definition: Line2.h:405
static bool fitLineLeastSquare(const VectorT2< T > *points, const size_t size, LineT2< T > &line)
Fits a line to a set of given image points by application of the least square measure.
Definition: Line2.h:580
void decomposeAngleDistance(T &angle, T &distance) const
Calculates the angle of the line's normal and the corresponding distance of this line to the origin.
Definition: Line2.h:366
VectorT3< T > decomposeNormalDistance(const bool forcePositiveDistance=false) const
Calculates the (implicit) three-parameters representation of this line composed of the line's normal ...
Definition: Line2.h:383
VectorT2< T > lineDirection
Direction of the line.
Definition: Line2.h:281
T distance(const VectorT2< T > &point) const
Returns the distance between the line and a given point.
Definition: Line2.h:486
const VectorT2< T > & direction() const
Returns the direction of the line.
Definition: Line2.h:348
friend class LineT2
Definition: Line2.h:84
T Type
Definition of the used data type.
Definition: Line2.h:91
T sqrDistance(const VectorT2< T > &point) const
Returns the square distance between the line and a given point.
Definition: Line2.h:498
VectorT2< T > linePoint
Point on the line.
Definition: Line2.h:278
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
VectorT2< T > nearestPoint(const VectorT2< T > &point) const
Returns the point on this line nearest to an arbitrary given point.
Definition: Line2.h:509
bool operator!=(const LineT2< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition: Line2.h:417
bool isOnLine(const VectorT2< T > &point) const
Returns whether a given point is part of the line.
Definition: Line2.h:429
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr T weakEps()
Returns a weak epsilon.
static T atan2(const T y, const T x)
Returns the arctangent of a given value in radian.
Definition: Numeric.h:1632
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition: Numeric.h:2386
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition: Numeric.h:1495
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition: Numeric.h:2087
This class implements a vector with two elements.
Definition: Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
T length() const
Returns the length of the vector.
Definition: Vector2.h:615
bool normalize()
Normalizes this vector.
Definition: Vector2.h:600
VectorT2< T > perpendicular() const
Returns a vector perpendicular to this vectors.
Definition: Vector2.h:550
This class implements a vector with three elements.
Definition: Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
std::vector< LineT2< T > > LinesT2
Definition of a typename alias for vectors with LineT2 objects.
Definition: Line2.h:50
float Scalar
Definition of a scalar type.
Definition: Math.h:128
LineT2< double > LineD2
Instantiation of the LineT2 template class using a double precision float data type.
Definition: Line2.h:35
std::vector< Line2 > Lines2
Definition of a vector holding Line2 objects.
Definition: Line2.h:57
LineT2< float > LineF2
Instantiation of the LineT2 template class using a single precision float data type.
Definition: Line2.h:42
LineT2< Scalar > Line2
Definition of the Line2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition: Line2.h:21
std::vector< LineD2 > LinesD2
Definition of a vector holding Line2 objects with double precision float data type.
Definition: Line2.h:71
std::vector< LineF2 > LinesF2
Definition of a vector holding Line2 objects with single precision float data type.
Definition: Line2.h:64
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15