8#ifndef META_OCEAN_MATH_LINE_3_H
9#define META_OCEAN_MATH_LINE_3_H
20template <
typename T>
class LineT3;
70 template <
typename U>
friend class LineT3;
242 explicit inline operator bool()
const;
356 return !(*
this == right);
372 const T length = offset.
length();
380 if (!std::is_same<T, float>::value)
398 const float length = offset.
length();
422 return (pointOnLine -
point).length();
462 return (pointOnLine -
point).sqr();
485 middle = (first + second) * T(0.5);
506 const T denominator = d.
sqr();
513 const T factor = - (p * d) / denominator;
524 static_assert(std::is_same<float, T>::value || std::is_same<double, T>::value,
"Type T can be either float or double.");
525 ocean_assert(points !=
nullptr && size >= 2);
530 for (
size_t i = 0; i < size; ++i)
532 centroid += points[i];
535 ocean_assert(size != 0);
536 const T invSize = T(1) / T(size);
547 for (
size_t i = 0; i < size; ++i)
551 cxx += diff.
x() * diff.
x();
552 cxy += diff.
x() * diff.
y();
553 cxz += diff.
x() * diff.
z();
554 cyy += diff.
y() * diff.
y();
555 cyz += diff.
y() * diff.
z();
556 czz += diff.
z() * diff.
z();
560 const SquareMatrixT3<T> covarianceMatrix(cxx, cxy, cxz, cxy, cyy, cyz, cxz, cyz, czz);
576 constexpr unsigned int maxIterations = 100u;
578 for (
unsigned int iteration = 0u; iteration < maxIterations; ++iteration)
581 const T length = newDirection.
length();
588 const VectorT3<T> normalizedDirection = newDirection / length;
This class implements an infinite line in 3D space.
Definition Line3.h:69
T distance(const LineT3< T > &line) const
Returns the distance between two lines.
Definition Line3.h:426
LineT3(const VectorT3< T > &point, const VectorT3< T > &direction)
Creates a line defined by two different intersection points.
Definition Line3.h:264
bool isParallel(const LineT3< T > &right) const
Returns whether two lines are parallel up to a small epsilon.
Definition Line3.h:324
static bool fitLineLeastSquare(const VectorT3< T > *points, const size_t size, LineT3< T > &line)
Fits a line to a set of given 3D points by application of the least square measure.
Definition Line3.h:522
const VectorT3< T > point(const T distance) const
Returns a point on the line that is defined by a scalar.
Definition Line3.h:286
bool operator==(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition Line3.h:346
void setPoint(const VectorT3< T > &point)
Sets a point of this line.
Definition Line3.h:299
LineT3(const LineT3< U > &line)
Copies a line with different data type than T.
Definition Line3.h:273
VectorT3< Scalar > direction_
Definition Line3.h:260
Scalar Type
Definition Line3.h:77
T sqrDistance(const VectorT3< T > &point) const
Returns the square distance between the line and a given point.
Definition Line3.h:455
bool isOnLine(const VectorT3< T > &point) const
Returns whether a given point is part of the line.
Definition Line3.h:366
void setDirection(const VectorT3< T > &direction)
Sets the direction of this line.
Definition Line3.h:305
bool isValid() const
Returns whether this line has valid parameters.
Definition Line3.h:312
const VectorT3< Scalar > & direction() const
bool nearestPoints(const LineT3< T > &line, VectorT3< T > &first, VectorT3< T > &second) const
Returns the two nearest points for two crossing lines.
Definition Line3.h:493
VectorT3< T > nearestPoint(const VectorT3< T > &point) const
Returns the point on this line nearest to an arbitrary given point.
Definition Line3.h:466
friend class LineT3
Definition Line3.h:70
const VectorT3< Scalar > & point() const
LineT3()=default
Creates an invalid line.
VectorT3< Scalar > point_
Definition Line3.h:257
Scalar distance(const VectorT3< Scalar > &point) const
bool nearestPoint(const LineT3< T > &line, VectorT3< T > &middle) const
Returns the middle of two nearest points for two crossing lines.
Definition Line3.h:477
bool isParallel(const VectorT3< T > &right) const
Returns whether this line and a given vector are parallel up to a small epsilon.
Definition Line3.h:335
bool hasUnitDirection() const
Returns whether this line has a unit vector as direction.
Definition Line3.h:318
bool operator!=(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition Line3.h:354
static constexpr T weakEps()
Returns a weak epsilon.
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
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 bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
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
VectorT3< T > normalized() const
Returns the normalized vector.
Definition Vector3.h:609
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector3.h:858
T length() const
Returns the length of the vector.
Definition Vector3.h:668
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:674
std::vector< LineT3< T > > LinesT3
Definition of a typename alias for vectors with LineT3 objects.
Definition Line3.h:49
LineT3< double > LineD3
Instantiation of the LineT3 template class using a double precision float data type.
Definition Line3.h:34
std::vector< Line3 > Lines3
Definition of a vector holding Line3 objects.
Definition Line3.h:56
LineT3< float > LineF3
Instantiation of the LineT3 template class using a single precision float data type.
Definition Line3.h:41
LineT3< Scalar > Line3
Definition of the Line3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Line3.h:27
The namespace covering the entire Ocean framework.
Definition Accessor.h:15