8#ifndef META_OCEAN_MATH_LINE_3_H
9#define META_OCEAN_MATH_LINE_3_H
19template <
typename T>
class LineT3;
69 template <
typename U>
friend class LineT3;
241 explicit inline operator bool()
const;
255 direction_(direction)
277 ocean_assert(isValid());
278 return point_ + direction_ * distance;
297 direction_ = direction;
303 return !direction_.
isNull();
315 ocean_assert(isValid() && right.
isValid());
318 const T scalarProduct = direction_ * right.
direction_;
326 ocean_assert(isValid());
329 const T scalarProduct = direction_ * right;
337 ocean_assert(isValid() && right.
isValid());
339 return isParallel(right) && isOnLine(right.
point());
345 return !(*
this == right);
357 ocean_assert(isValid());
358 ocean_assert(hasUnitDirection());
361 const T length = offset.
length();
369 if (!std::is_same<T, float>::value)
383 ocean_assert(isValid());
384 ocean_assert(hasUnitDirection());
387 const float length = offset.
length();
406 ocean_assert(isValid());
407 ocean_assert(hasUnitDirection());
409 const VectorT3<T> pointOnLine(nearestPoint(point));
411 return (pointOnLine - point).length();
420 ocean_assert(isValid() && line.
isValid());
431 if (isParallel(line))
433 return (line.
point_ - point_ + direction_ * (direction_ * offset)).length();
446 ocean_assert(isValid());
447 ocean_assert(hasUnitDirection());
449 const VectorT3<T> pointOnLine(nearestPoint(point));
451 return (pointOnLine - point).sqr();
457 ocean_assert(isValid());
458 ocean_assert(hasUnitDirection());
462 return point_ + direction_ * (direction_ * offset);
468 ocean_assert(isValid() && line.
isValid());
472 if (nearestPoints(line, first, second))
474 middle = (first + second) * T(0.5);
484 ocean_assert(isValid() && line.
isValid());
487 if (isParallel(line))
495 const T denominator = d.
sqr();
502 const T factor = - (p * d) / denominator;
505 first = nearestPoint(second);
This class implements an infinite line in 3D space.
Definition Line3.h:68
bool isParallel(const LineT3< T > &right) const
Returns whether two lines are parallel up to a small epsilon.
Definition Line3.h:313
bool operator==(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition Line3.h:335
void setPoint(const VectorT3< T > &point)
Sets a point of this line.
Definition Line3.h:288
VectorT3< T > direction_
Direction of the line.
Definition Line3.h:249
T sqrDistance(const VectorT3< T > &point) const
Returns the square distance between the line and a given point.
Definition Line3.h:444
bool isOnLine(const VectorT3< T > &point) const
Returns whether a given point is part of the line.
Definition Line3.h:355
void setDirection(const VectorT3< T > &direction)
Sets the direction of this line.
Definition Line3.h:294
bool isValid() const
Returns whether this line has valid parameters.
Definition Line3.h:301
const VectorT3< T > & direction() const
Returns the direction of the line.
Definition Line3.h:282
T Type
Definition of the used data type.
Definition Line3.h:76
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:482
VectorT3< T > nearestPoint(const VectorT3< T > &point) const
Returns the point on this line nearest to an arbitrary given point.
Definition Line3.h:455
friend class LineT3
Definition Line3.h:69
const VectorT3< T > & point() const
Returns a point on the line.
Definition Line3.h:269
LineT3()=default
Creates an invalid line.
VectorT3< T > point_
Point on the line.
Definition Line3.h:246
T distance(const VectorT3< T > &point) const
Returns the distance between the line and a given point.
Definition Line3.h:404
bool hasUnitDirection() const
Returns whether this line has a unit vector as direction.
Definition Line3.h:307
bool operator!=(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition Line3.h:343
This class provides basic numeric functionalities.
Definition Numeric.h:57
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2386
This class implements a vector with three elements.
Definition Vector3.h:97
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector3.h:866
T length() const
Returns the length of the vector.
Definition Vector3.h:676
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:682
LineT3< Scalar > Line3
Definition of the Line3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Line3.h:26
LineT3< double > LineD3
Instantiation of the LineT3 template class using a double precision float data type.
Definition Line3.h:33
std::vector< Line3 > Lines3
Definition of a vector holding Line3 objects.
Definition Line3.h:55
LineT3< float > LineF3
Instantiation of the LineT3 template class using a single precision float data type.
Definition Line3.h:40
std::vector< LineT3< T > > LinesT3
Definition of a typename alias for vectors with LineT3 objects.
Definition Line3.h:48
The namespace covering the entire Ocean framework.
Definition Accessor.h:15