8 #ifndef META_OCEAN_MATH_PLANE_3_H
9 #define META_OCEAN_MATH_PLANE_3_H
21 template <
typename T>
class LineT3;
24 template <
typename T>
class PlaneT3;
253 explicit inline operator bool()
const;
285 template <
typename T>
288 distance_(point * normal_)
293 template <
typename T>
299 if (direction10 != direction20 && direction10 != -direction20)
301 normal_ = direction10.
cross(direction20).normalizedOrZero();
302 distance_ = point0 * normal_;
306 template <
typename T>
314 template <
typename T>
324 template <
typename T>
326 normal_(transformation.zAxis()),
339 template <
typename T>
345 template <
typename T>
351 template <
typename T>
354 ocean_assert(isValid());
360 template <
typename T>
363 ocean_assert(isValid() && iTransformation.
isValid());
368 const VectorT3<T> pointOnNewPlane(iTransformation * pointOnPlane());
371 const T distance = pointOnNewPlane * normal;
379 template <
typename T>
382 ocean_assert(isValid());
385 ocean_assert(!normal_.isParallel(upVector));
392 VectorT3<T> yAxis = projectOnPlane(pointOnPlane + upVector) - pointOnPlane;
412 template <
typename T>
419 template <
typename T>
422 distance_ = distance;
425 template <
typename T>
429 return normal_ * distance_;
432 template <
typename T>
435 ocean_assert(isValid());
440 template <
typename T>
443 ocean_assert(isValid());
445 return point * normal_ - distance_;
448 template <
typename T>
451 ocean_assert(isValid());
453 const VectorT3<T> result(point - normal_ * signedDistance(point));
461 template <
typename T>
464 ocean_assert(isValid());
468 return direction - normal_ * (T(2.0) * (direction * normal_));
471 template <
typename T>
474 ocean_assert(isValid());
482 const T denominator(normal_ * ray.
direction());
490 const T factor = (distance_ - normal_ * ray.
point()) / denominator;
493 ocean_assert((std::is_same<T, float>::value) ||
NumericT<T>::isWeakEqualEps((point - pointOnPlane()).normalizedOrZero() * normal_));
498 template <
typename T>
501 ocean_assert(isValid());
508 VectorT3<T> normalizedLineDirection = lineDirection;
509 if (!normalizedLineDirection.
normalize())
515 const T dotProduct = lineDirection * lineDirection;
532 line =
LineT3<T>(linePoint, normalizedLineDirection);
537 template <
typename T>
543 template <
typename T>
546 ocean_assert(isValid());
552 template <
typename T>
555 return !normal_.isNull();
558 template <
typename T>
561 ocean_assert(isValid());
563 const PlaneT3<T> result(-normal_, -distance_);
570 template <
typename T>
573 ocean_assert(isValid());
575 return isEqual(right);
578 template <
typename T>
581 return !(*
this == right);
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition: HomogenousMatrix4.h:110
HomogenousMatrixT4< T > inverted() const noexcept
Returns the inverted of this matrix.
Definition: HomogenousMatrix4.h:1575
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition: HomogenousMatrix4.h:1493
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
This class implements an infinite line in 3D space.
Definition: Line3.h:70
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
const VectorT3< T > & point() const
Returns a point on the line.
Definition: Line3.h:271
This class provides basic numeric functionalities.
Definition: Numeric.h:57
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 T cos(const T value)
Returns the cosine of a given value.
Definition: Numeric.h:1584
static T asin(const T value)
Returns the arcsine of a given value.
Definition: Numeric.h:2887
bool intersection(const LineT3< T > &ray, VectorT3< T > &point) const
Calculates the intersection between this plane and a given ray.
Definition: Plane3.h:472
bool operator!=(const PlaneT3< T > &right) const
Returns whether two plane objects do not represent the same plane.
Definition: Plane3.h:579
PlaneT3(const VectorT3< T > &point, const VectorT3< T > &normal)
Creates a plane by an intersection point and a normal.
Definition: Plane3.h:286
PlaneT3()=default
Creates an invalid plane.
PlaneT3(const HomogenousMatrixT4< T > &transformation)
Creates a plane by a transformation where the z-axis defined the plane's normal and the origin or the...
Definition: Plane3.h:325
const VectorT3< T > & normal() const
Returns the normal of the plane.
Definition: Plane3.h:340
bool transformation(const VectorT3< T > &pointOnPlane, const VectorT3< T > &upVector, HomogenousMatrixT4< T > &matrix) const
Determines a transformation having the origin in a given point on the plane, with z-axis correspondin...
Definition: Plane3.h:380
void setNormal(const VectorT3< T > &normal)
Sets the normal of this plane.
Definition: Plane3.h:413
T signedDistance(const VectorT3< T > &point) const
Returns the distance between a given point and this plane.
Definition: Plane3.h:441
VectorT3< T > normal_
Normal of the plane.
Definition: Plane3.h:279
bool isInPlane(const VectorT3< T > &point, const T epsilon=NumericT< T >::eps()) const
Returns whether a point is in the plane.
Definition: Plane3.h:433
bool operator==(const PlaneT3< T > &right) const
Returns whether two plane objects represent the same plane.
Definition: Plane3.h:571
bool intersection(const PlaneT3< T > &plane, LineT3< T > &line) const
Calculates the intersection between this plane and a second plane.
Definition: Plane3.h:499
PlaneT3(const VectorT3< T > &normal, const T distance)
Creates a plane by the plane's normal and the distance between origin and plane.
Definition: Plane3.h:307
PlaneT3(const VectorT3< T > &point0, const VectorT3< T > &point1, const VectorT3< T > &point2)
Creates a plane by three points lying in the plane.
Definition: Plane3.h:294
VectorT3< T > pointOnPlane() const
Returns a point on the plane.
Definition: Plane3.h:426
T Type
Definition of the used data type.
Definition: Plane3.h:79
PlaneT3< T > transform(const HomogenousMatrixT4< T > &iTransformation) const
Transforms this plane so that it corresponds to a new coordinate system.
Definition: Plane3.h:361
T distance_
Distance of the plane.
Definition: Plane3.h:282
VectorT3< T > reflect(const VectorT3< T > &direction)
Reflects a given vector in the plane.
Definition: Plane3.h:462
void setDistance(const T distance)
Sets the distance between plane and origin.
Definition: Plane3.h:420
bool isValid() const
Returns whether this plane is valid.
Definition: Plane3.h:538
VectorT3< T > projectOnPlane(const VectorT3< T > &point) const
Projects a given point onto the plane.
Definition: Plane3.h:449
void decomposeNormal(T &yaw, T &pitch) const
Calculates the yaw and pitch angle of the plane's normal.
Definition: Plane3.h:352
PlaneT3(const T yaw, const T pitch, const T distance)
Creates a plane by the plane's normal and the distance between origin and plane.
Definition: Plane3.h:315
PlaneT3< T > operator-() const
Returns an inverted plane of this plane having an inverted normal direction (and adjusted distance).
Definition: Plane3.h:559
const T & distance() const
Returns the distance between plane and origin.
Definition: Plane3.h:346
bool isEqual(const PlaneT3< T > &plane, const T eps=NumericT< T >::eps()) const
Returns whether two plane objects represent the same plane up to a specified epsilon.
Definition: Plane3.h:544
This class implements a vector with three elements.
Definition: Vector3.h:97
bool normalize()
Normalizes this vector.
Definition: Vector3.h:647
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition: Vector3.h:597
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
PlaneT3< double > PlaneD3
Definition of a 3D plane with double values.
Definition: Plane3.h:38
PlaneT3< float > PlaneF3
Definition of a 3D plane with float values.
Definition: Plane3.h:45
std::vector< PlaneT3< T > > PlanesT3
Definition of a typename alias for vectors with PlaneT3 objects.
Definition: Plane3.h:53
PlaneT3< Scalar > Plane3
Definition of the Plane3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition: Plane3.h:24
std::vector< Plane3 > Planes3
Definition of a vector holding Plane3 objects.
Definition: Plane3.h:60
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15