8#ifndef META_OCEAN_MATH_LINE_2_H
9#define META_OCEAN_MATH_LINE_2_H
21template <
typename T>
class LineT2;
84 template <
typename U>
friend class LineT2;
129 template <
typename U>
264 explicit inline operator bool()
const;
396 if (forcePositiveDistance &&
distance < T(0))
419 return !(*
this == right);
435 const T length = offset.
length();
443 if (!std::is_same<T, float>::value)
469 const float length = offset.
length();
492 ocean_assert((!std::is_same<T, double>::value) ||
isOnLine(pointOnLine));
494 return (pointOnLine -
point).length();
505 return (pointOnLine -
point).sqr();
533 const T normalLength =
normal.length();
550 const T offset = normalLength / cosValue;
554 if constexpr (std::is_same<T, double>::value)
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++)
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
LineT2(const VectorT3< T > ¶meters)
Creates a new line object by given (implicit) three-parameter representation of the line.
Definition Line2.h:301
const VectorT2< Scalar > & point() const
bool hasUnitDirection() const
Returns whether this line has a unit vector as direction.
Definition Line2.h:411
VectorT2< T > point(const T distance) const
Returns a point on the line that is defined by a scalar.
Definition Line2.h:341
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
LineT2(const T angle, const T distance)
Creates a new line object by a given angle of the line's normal and the distance of the line to the o...
Definition Line2.h:314
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
LineT2()
Creates an invalid line.
Definition Line2.h:285
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
LineT2(const LineT2< U > &line)
Copies a line with different data type than T.
Definition Line2.h:328
VectorT2< Scalar > lineDirection
Definition Line2.h:281
Scalar Type
Definition Line2.h:91
Scalar distance(const VectorT2< Scalar > &point) const
const VectorT2< Scalar > & direction() const
friend class LineT2
Definition Line2.h:84
T sqrDistance(const VectorT2< T > &point) const
Returns the square distance between the line and a given point.
Definition Line2.h:498
VectorT2< Scalar > linePoint
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
LineT2(const VectorT2< T > &point, const VectorT2< T > &direction)
Creates a line defined by a point on the line and a line direction.
Definition Line2.h:293
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:1636
static T sin(const T value)
Returns the sine of a given value.
Definition Numeric.h:1572
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static bool isWeakEqual(const T first, const T second)
Returns whether two values a equal up to a weak epsilon.
Definition Numeric.h:2581
static constexpr bool isWeakEqualEps(const T value)
Returns whether a value is smaller than or equal to a weak epsilon.
Definition Numeric.h:2171
static constexpr T eps()
Returns a small epsilon.
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
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
T length() const
Returns the length of the vector.
Definition Vector2.h:620
bool normalize()
Normalizes this vector.
Definition Vector2.h:605
This class implements a vector with three elements.
Definition Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
LineT2< double > LineD2
Instantiation of the LineT2 template class using a double precision float data type.
Definition Line2.h:35
LineT2< Scalar > Line2
Definition of the Line2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Line2.h:28
std::vector< LineD2 > LinesD2
Definition of a vector holding Line2 objects with double precision float data type.
Definition Line2.h:71
LineT2< float > LineF2
Instantiation of the LineT2 template class using a single precision float data type.
Definition Line2.h:42
std::vector< LineF2 > LinesF2
Definition of a vector holding Line2 objects with single precision float data type.
Definition Line2.h:64
std::vector< Line2 > Lines2
Definition of a vector holding Line2 objects.
Definition Line2.h:57
std::vector< LineT2< T > > LinesT2
Definition of a typename alias for vectors with LineT2 objects.
Definition Line2.h:50
The namespace covering the entire Ocean framework.
Definition Accessor.h:15