8 #ifndef META_OCEAN_MATH_TRIANGLE_3_H
9 #define META_OCEAN_MATH_TRIANGLE_3_H
21 template <
typename T>
class TriangleT3;
261 template <
typename T>
269 template <
typename T>
272 trianglePoints[0] = point0;
273 trianglePoints[1] = point1;
274 trianglePoints[2] = point2;
277 template <
typename T>
280 return trianglePoints[0];
283 template <
typename T>
286 return trianglePoints[1];
289 template <
typename T>
292 return trianglePoints[2];
295 template <
typename T>
300 return VectorT3<T>((trianglePoints[0].x() * barycentric[0] + trianglePoints[1].x() * barycentric[1] + trianglePoints[2].x() * barycentric[2]),
301 (trianglePoints[0].y() * barycentric[0] + trianglePoints[1].y() * barycentric[1] + trianglePoints[2].y() * barycentric[2]),
302 (trianglePoints[0].z() * barycentric[0] + trianglePoints[1].z() * barycentric[1] + trianglePoints[2].z() * barycentric[2]));
305 template <
typename T>
322 template <
typename T>
341 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
346 distance = result.
z();
352 template <
typename T>
366 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
371 distance = result.
z();
373 barycentric =
VectorT3<T>(1 - result.
x() - result.
y(), result.
x(), result.
y());
378 template <
typename T>
392 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
397 distance = result.
z();
399 const VectorT3<T> normal((trianglePoints[1] - trianglePoints[0]).cross(trianglePoints[2] - trianglePoints[0]));
405 ocean_assert(reflection.
isValid());
410 template <
typename T>
424 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
429 distance = result.
z();
431 normal =
VectorT3<T>((trianglePoints[1] - trianglePoints[0]).cross(trianglePoints[2] - trianglePoints[0]));
437 ocean_assert(reflection.
isValid());
442 template <
typename T>
462 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
467 distance = result.
z();
472 ocean_assert(reflection.
isValid());
477 template <
typename T>
495 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
500 distance = result.
z();
502 const VectorT3<T> normal(normal0 * (1 - result.
x() - result.
y()) + normal1 * result.
x() + normal2 * result.
y());
513 ocean_assert(reflection.
isValid());
518 template <
typename T>
536 if (result.
x() < 0 || result.
y() < 0 || result.
x() + result.
y() > 1)
541 distance = result.
z();
543 normal =
VectorT3<T>(normal0 * (1 - result.
x() - result.
y()) + normal1 * result.
x() + normal2 * result.
y());
555 ocean_assert(reflection.
isValid());
560 template <
typename T>
574 barycentric =
VectorT3<T>(1 - result.
x() - result.
y(), result.
x(), result.
y());
579 template <
typename T>
582 return trianglePoints[0] != trianglePoints[1] && trianglePoints[0] != trianglePoints[2] && trianglePoints[1] != trianglePoints[2];
585 template <
typename T>
588 ocean_assert(index <= 2u);
589 return trianglePoints[index];
592 template <
typename T>
595 return TriangleT3<T>(trianglePoints[0] + offset, trianglePoints[1] + offset, trianglePoints[2] + offset);
598 template <
typename T>
601 trianglePoints[0] += offset;
602 trianglePoints[1] += offset;
603 trianglePoints[2] += offset;
608 template <
typename T>
611 return TriangleT3<T>(trianglePoints[0] - offset, trianglePoints[1] - offset, trianglePoints[2] - offset);
614 template <
typename T>
617 trianglePoints[0] -= offset;
618 trianglePoints[1] -= offset;
619 trianglePoints[2] -= offset;
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 constexpr T eps()
Returns a small epsilon.
This class implements a 3x3 square matrix.
Definition: SquareMatrix3.h:88
bool invert()
Inverts this matrix in place.
Definition: SquareMatrix3.h:1190
This class implements a 3D triangle.
Definition: Triangle3.h:80
TriangleT3< T > & operator-=(const VectorT3< T > &offset)
Shifts the triangle by a given 3D vector (by subtracting the vector from all three corners of the tri...
Definition: Triangle3.h:615
TriangleT3< T > & operator+=(const VectorT3< T > &offset)
Shifts the triangle by a given 3D vector (by adding the vector to all three corners of the triangle).
Definition: Triangle3.h:599
const VectorT3< T > & point0() const
Returns the first point of this triangle.
Definition: Triangle3.h:278
const VectorT3< T > & operator[](const unsigned int index) const
Returns individual triangle corners.
Definition: Triangle3.h:586
bool frontIntersection(const LineT3< T > &ray, const VectorT3< T > &normal, LineT3< T > &reflection, T &distance) const
Returns whether a given ray has a front intersection with this triangle and determines the reflective...
Definition: Triangle3.h:443
bool planeIntersection(const LineT3< T > &ray, VectorT3< T > &barycentric) const
Returns the intersection point with a given ray and a plane that is spanned by this triangle.
Definition: Triangle3.h:561
VectorT3< T > barycentric2cartesian(const VectorT3< T > &barycentric) const
Returns the 3D cartesian coordinate of a given barycentric coordinate defined in relation to this tri...
Definition: Triangle3.h:296
bool isValid() const
Returns whether this triangle is valid.
Definition: Triangle3.h:580
bool hasIntersection(const LineT3< T > &ray) const
Returns whether a given ray has an intersection with this triangle.
Definition: Triangle3.h:306
TriangleT3< T > operator+(const VectorT3< T > &offset) const
Shifts the triangle by a given 3D vector (by adding the vector to all three corners of the triangle).
Definition: Triangle3.h:593
const VectorT3< T > & point2() const
Returns the third point of this triangle.
Definition: Triangle3.h:290
TriangleT3< T > operator-(const VectorT3< T > &offset) const
Shifts the triangle by a given 3D vector (by subtracting the vector from all three corners of the tri...
Definition: Triangle3.h:609
const VectorT3< T > & point1() const
Returns the second point of this triangle.
Definition: Triangle3.h:284
bool intersection(const LineT3< T > &ray, VectorT3< T > &point, T &distance) const
Returns whether a given ray has an intersection with this triangle and determines the intersection po...
Definition: Triangle3.h:323
TriangleT3()
Creates a new triangle object with default parameters.
Definition: Triangle3.h:262
VectorT3< T > trianglePoints[3]
Three triangle points.
Definition: Triangle3.h:258
This class implements a base class for all triangle classes.
Definition: Triangle.h:49
This class implements a vector with three elements.
Definition: Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
bool normalize()
Normalizes this vector.
Definition: Vector3.h:647
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
TriangleT3< Scalar > Triangle3
Definition of the Triangle3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition: Triangle3.h:21
std::vector< TriangleD3 > TrianglesD3
Definition of a vector holding 3D triangles with double precision float data type.
Definition: Triangle3.h:71
std::vector< TriangleF3 > TrianglesF3
Definition of a vector holding 3D triangles with single precision float data type.
Definition: Triangle3.h:64
TriangleT3< double > TriangleD3
Instantiation of the TriangleT3 template class using a double precision float data type.
Definition: Triangle3.h:35
std::vector< TriangleT3< T > > TrianglesT3
Definition of a typename alias for vectors with TriangleT3 objects.
Definition: Triangle3.h:50
TriangleT3< float > TriangleF3
Instantiation of the TriangleT3 template class using a single precision float data type.
Definition: Triangle3.h:42
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition: Triangle3.h:57
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15