8 #ifndef META_OCEAN_MATH_LINE_3_H
9 #define META_OCEAN_MATH_LINE_3_H
21 template <
typename T>
class LineT3;
71 template <
typename U>
friend class LineT3;
243 explicit inline operator bool()
const;
254 template <
typename T>
257 direction_(direction)
262 template <
typename T>
263 template <
typename U>
270 template <
typename T>
276 template <
typename T>
279 ocean_assert(isValid());
280 return point_ + direction_ * distance;
283 template <
typename T>
289 template <
typename T>
295 template <
typename T>
299 direction_ = direction;
302 template <
typename T>
305 return !direction_.isNull();
308 template <
typename T>
314 template <
typename T>
317 ocean_assert(isValid() && right.
isValid());
320 const T scalarProduct = direction_ * right.
direction_;
325 template <
typename T>
328 ocean_assert(isValid());
331 const T scalarProduct = direction_ * right;
336 template <
typename T>
339 ocean_assert(isValid() && right.
isValid());
341 return isParallel(right) && isOnLine(right.
point());
344 template <
typename T>
347 return !(*
this == right);
350 template <
typename T>
356 template <
typename T>
359 ocean_assert(isValid());
360 ocean_assert(hasUnitDirection());
363 const T length = offset.
length();
371 if (!std::is_same<T, float>::value)
385 ocean_assert(isValid());
386 ocean_assert(hasUnitDirection());
389 const float length = offset.
length();
405 template <
typename T>
408 ocean_assert(isValid());
409 ocean_assert(hasUnitDirection());
411 const VectorT3<T> pointOnLine(nearestPoint(point));
413 return (pointOnLine - point).length();
416 template <
typename T>
422 ocean_assert(isValid() && line.
isValid());
433 if (isParallel(line))
435 return (line.
point_ - point_ + direction_ * (direction_ * offset)).length();
445 template <
typename T>
448 ocean_assert(isValid());
449 ocean_assert(hasUnitDirection());
451 const VectorT3<T> pointOnLine(nearestPoint(point));
453 return (pointOnLine - point).sqr();
456 template <
typename T>
459 ocean_assert(isValid());
460 ocean_assert(hasUnitDirection());
464 return point_ + direction_ * (direction_ * offset);
467 template <
typename T>
470 ocean_assert(isValid() && line.
isValid());
474 if (nearestPoints(line, first, second))
476 middle = (first + second) * T(0.5);
483 template <
typename T>
486 ocean_assert(isValid() && line.
isValid());
489 if (isParallel(line))
497 const T denominator = d.
sqr();
504 const T factor = - (p * d) / denominator;
507 first = nearestPoint(second);
This class implements an infinite line in 3D space.
Definition: Line3.h:70
bool isParallel(const LineT3< T > &right) const
Returns whether two lines are parallel up to a small epsilon.
Definition: Line3.h:315
bool operator==(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition: Line3.h:337
void setPoint(const VectorT3< T > &point)
Sets a point of this line.
Definition: Line3.h:290
VectorT3< T > direction_
Direction of the line.
Definition: Line3.h:251
T sqrDistance(const VectorT3< T > &point) const
Returns the square distance between the line and a given point.
Definition: Line3.h:446
bool isOnLine(const VectorT3< T > &point) const
Returns whether a given point is part of the line.
Definition: Line3.h:357
void setDirection(const VectorT3< T > &direction)
Sets the direction of this line.
Definition: Line3.h:296
bool isValid() const
Returns whether this line has valid parameters.
Definition: Line3.h:303
const VectorT3< T > & direction() const
Returns the direction of the line.
Definition: Line3.h:284
T Type
Definition of the used data type.
Definition: Line3.h:78
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:484
VectorT3< T > nearestPoint(const VectorT3< T > &point) const
Returns the point on this line nearest to an arbitrary given point.
Definition: Line3.h:457
friend class LineT3
Definition: Line3.h:71
const VectorT3< T > & point() const
Returns a point on the line.
Definition: Line3.h:271
LineT3()=default
Creates an invalid line.
VectorT3< T > point_
Point on the line.
Definition: Line3.h:248
T distance(const VectorT3< T > &point) const
Returns the distance between the line and a given point.
Definition: Line3.h:406
bool hasUnitDirection() const
Returns whether this line has a unit vector as direction.
Definition: Line3.h:309
bool operator!=(const LineT3< T > &right) const
Returns whether two line are identical up to a small epsilon.
Definition: Line3.h:345
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
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
T sqr() const
Returns the square of the vector length.
Definition: Vector3.h:670
LineT3< Scalar > Line3
Definition of the Line3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition: Line3.h:21
LineT3< double > LineD3
Instantiation of the LineT3 template class using a double precision float data type.
Definition: Line3.h:35
std::vector< Line3 > Lines3
Definition of a vector holding Line3 objects.
Definition: Line3.h:57
LineT3< float > LineF3
Instantiation of the LineT3 template class using a single precision float data type.
Definition: Line3.h:42
std::vector< LineT3< T > > LinesT3
Definition of a typename alias for vectors with LineT3 objects.
Definition: Line3.h:50
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15