Ocean
Triangle3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MATH_TRIANGLE_3_H
9 #define META_OCEAN_MATH_TRIANGLE_3_H
10 
11 #include "ocean/math/Math.h"
12 #include "ocean/math/Line3.h"
14 #include "ocean/math/Triangle.h"
15 #include "ocean/math/Vector3.h"
16 
17 namespace Ocean
18 {
19 
20 // Forward declaration.
21 template <typename T> class TriangleT3;
22 
23 /**
24  * Definition of the Triangle3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single or double precision float data type.
25  * @see TriangleT3
26  * @ingroup math
27  */
29 
30 /**
31  * Instantiation of the TriangleT3 template class using a double precision float data type.
32  * @see TriangleT3
33  * @ingroup math
34  */
36 
37 /**
38  * Instantiation of the TriangleT3 template class using a single precision float data type.
39  * @see TriangleT3
40  * @ingroup math
41  */
43 
44 /**
45  * Definition of a typename alias for vectors with TriangleT3 objects.
46  * @see TriangleT3
47  * @ingroup math
48  */
49 template <typename T>
50 using TrianglesT3 = std::vector<TriangleT3<T>>;
51 
52 /**
53  * Definition of a vector holding 3D triangles.
54  * @see Triangle3
55  * @ingroup math
56  */
57 typedef std::vector<Triangle3> Triangles3;
58 
59 /**
60  * Definition of a vector holding 3D triangles with single precision float data type.
61  * @see Triangle3
62  * @ingroup math
63  */
64 typedef std::vector<TriangleF3> TrianglesF3;
65 
66 /**
67  * Definition of a vector holding 3D triangles with double precision float data type.
68  * @see Triangle3
69  * @ingroup math
70  */
71 typedef std::vector<TriangleD3> TrianglesD3;
72 
73 /**
74  * This class implements a 3D triangle.
75  * @see Triangle2.
76  * @ingroup math
77  */
78 template <typename T>
79 class TriangleT3 : public TriangleT<T>
80 {
81  public:
82 
83  /**
84  * Creates a new triangle object with default parameters.
85  */
86  inline TriangleT3();
87 
88  /**
89  * Creates a new triangle object by three given corners.
90  * @param point0 First triangle point
91  * @param point1 Second triangle point
92  * @param point2 Third triangle point
93  */
94  inline TriangleT3(const VectorT3<T>& point0, const VectorT3<T>& point1, const VectorT3<T>& point2);
95 
96  /**
97  * Returns the first point of this triangle.
98  * @return Triangle point
99  */
100  inline const VectorT3<T>& point0() const;
101 
102  /**
103  * Returns the second point of this triangle.
104  * @return Triangle point
105  */
106  inline const VectorT3<T>& point1() const;
107 
108  /**
109  * Returns the third point of this triangle.
110  * @return Triangle point
111  */
112  inline const VectorT3<T>& point2() const;
113 
114  /**
115  * Returns the 3D cartesian coordinate of a given barycentric coordinate defined in relation to this triangle.
116  * @param barycentric Barycentric coordinate to convert to a cartesian coordinate
117  * @return Cartesian coordinate
118  */
119  inline VectorT3<T> barycentric2cartesian(const VectorT3<T>& barycentric) const;
120 
121  /**
122  * Returns whether a given ray has an intersection with this triangle.
123  * @param ray Ray to determine whether an intersection occurs
124  * @return True, if so
125  */
126  inline bool hasIntersection(const LineT3<T>& ray) const;
127 
128  /**
129  * Returns whether a given ray has an intersection with this triangle and determines the intersection point.
130  * @param ray Ray to determine whether an intersection occurs
131  * @param point Resulting intersection point, if an intersection occurs
132  * @param distance Resulting intersection distance
133  * @return True, if so
134  */
135  bool intersection(const LineT3<T>& ray, VectorT3<T>& point, T& distance) const;
136 
137  /**
138  * Returns whether a given ray has an intersection with this triangle and determines the intersection point.
139  * @param ray Ray to determine whether an intersection occurs
140  * @param point Resulting intersection point, if an intersection occurs
141  * @param barycentric Resulting Barycentric intersection point
142  * @param distance Resulting intersection distance
143  * @return True, if so
144  */
145  bool intersection(const LineT3<T>& ray, VectorT3<T>& point, VectorT3<T>& barycentric, T& distance) const;
146 
147  /**
148  * Returns whether a given ray has an intersection with this triangle and determines the reflective ray starting at the intersection point.
149  * The reflection normal is determined by the triangle.<br>
150  * @param ray Ray to determine whether an intersection occurs
151  * @param reflection Resulting reflection ray, if an intersection occurs
152  * @param distance Resulting intersection distance
153  * @return True, if so
154  */
155  bool intersection(const LineT3<T>& ray, LineT3<T>& reflection, T& distance) const;
156 
157  /**
158  * Returns whether a given ray has an intersection with this triangle and determines the reflective ray starting at the intersection point.
159  * The reflection normal is determined by the triangle.<br>
160  * @param ray Ray to determine whether an intersection occurs
161  * @param reflection Resulting reflection ray, if an intersection occurs
162  * @param distance Resulting intersection distance
163  * @param normal Resulting normal
164  * @return True, if so
165  */
166  bool intersection(const LineT3<T>& ray, LineT3<T>& reflection, T& distance, VectorT3<T>& normal) const;
167 
168  /**
169  * Returns whether a given ray has a front intersection with this triangle and determines the reflective ray starting at the intersection point.
170  * An explicit reflection normal is used.<br>
171  * @param ray Ray to determine whether an intersection occurs
172  * @param normal Reflection normal
173  * @param reflection Resulting reflection ray, if an intersection occurs
174  * @param distance Resulting intersection distance
175  * @return True, if so
176  */
177  inline bool frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal, LineT3<T>& reflection, T& distance) const;
178 
179  /**
180  * Returns whether a given ray has a front intersection with this triangle and determines the reflective ray starting at the intersection point.
181  * The reflection normal is determined by interpolation of the given three point normals.
182  * @param ray Ray to determine whether an intersection occurs
183  * @param normal0 Normal of the first triangle point
184  * @param normal1 Normal of the second triangle point
185  * @param normal2 Normal of the third triangle point
186  * @param reflection Resulting reflection ray, if an intersection occurs
187  * @param distance Resulting intersection distance
188  * @return True, if so
189  */
190  inline bool frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal0, const VectorT3<T>& normal1, const VectorT3<T>& normal2, LineT3<T>& reflection, T& distance) const;
191 
192  /**
193  * Returns whether a given ray has a front intersection with this triangle and determines the reflective ray starting at the intersection point.
194  * The reflection normal is determined by interpolation of the given three point normals.
195  * @param ray Ray to determine whether an intersection occurs
196  * @param normal0 Normal of the first triangle point
197  * @param normal1 Normal of the second triangle point
198  * @param normal2 Normal of the third triangle point
199  * @param reflection Resulting reflection ray, if an intersection occurs
200  * @param distance Resulting intersection distance
201  * @param normal Resulting normal
202  * @return True, if so
203  */
204  inline bool frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal0, const VectorT3<T>& normal1, const VectorT3<T>& normal2, LineT3<T>& reflection, T& distance, VectorT3<T>& normal) const;
205 
206  /**
207  * Returns the intersection point with a given ray and a plane that is spanned by this triangle.
208  * @param ray Ray to determine whether an intersection occurs
209  * @param barycentric Resulting Barycentric intersection point
210  * @return True, if the ray intersects the plane that is spanned by the triangle (the return value does not indicate whether the triangle itself has been intersected)
211  */
212  bool planeIntersection(const LineT3<T>& ray, VectorT3<T>& barycentric) const;
213 
214  /**
215  * Returns whether this triangle is valid.
216  * @return True, if so
217  */
218  inline bool isValid() const;
219 
220  /**
221  * Returns individual triangle corners.
222  * @param index Index of the corner that is requested, with range [0, 2]
223  * @return Resulting triangle corner
224  */
225  inline const VectorT3<T>& operator[](const unsigned int index) const;
226 
227  /**
228  * Shifts the triangle by a given 3D vector (by adding the vector to all three corners of the triangle).
229  * @param offset The offset vector to shift the triangle
230  * @return The new shifted triangle
231  */
232  inline TriangleT3<T> operator+(const VectorT3<T>& offset) const;
233 
234  /**
235  * Shifts the triangle by a given 3D vector (by adding the vector to all three corners of the triangle).
236  * @param offset The offset vector to shift the triangle
237  * @return The reference to this triangle
238  */
239  inline TriangleT3<T>& operator+=(const VectorT3<T>& offset);
240 
241  /**
242  * Shifts the triangle by a given 3D vector (by subtracting the vector from all three corners of the triangle).
243  * @param offset The offset vector to shift the triangle
244  * @return The new shifted triangle
245  */
246  inline TriangleT3<T> operator-(const VectorT3<T>& offset) const;
247 
248  /**
249  * Shifts the triangle by a given 3D vector (by subtracting the vector from all three corners of the triangle).
250  * @param offset The offset vector to shift the triangle
251  * @return The reference to this triangle
252  */
253  inline TriangleT3<T>& operator-=(const VectorT3<T>& offset);
254 
255  private:
256 
257  /// Three triangle points.
259 };
260 
261 template <typename T>
263 {
264  trianglePoints[0] = VectorT3<T>(0, 0, 0);
265  trianglePoints[1] = VectorT3<T>(0, 0, 0);
266  trianglePoints[2] = VectorT3<T>(0, 0, 0);
267 }
268 
269 template <typename T>
270 inline TriangleT3<T>::TriangleT3(const VectorT3<T>& point0, const VectorT3<T>& point1, const VectorT3<T>& point2)
271 {
272  trianglePoints[0] = point0;
273  trianglePoints[1] = point1;
274  trianglePoints[2] = point2;
275 }
276 
277 template <typename T>
278 inline const VectorT3<T>& TriangleT3<T>::point0() const
279 {
280  return trianglePoints[0];
281 }
282 
283 template <typename T>
284 inline const VectorT3<T>& TriangleT3<T>::point1() const
285 {
286  return trianglePoints[1];
287 }
288 
289 template <typename T>
290 inline const VectorT3<T>& TriangleT3<T>::point2() const
291 {
292  return trianglePoints[2];
293 }
294 
295 template <typename T>
297 {
298  ocean_assert(TriangleT<T>::isValidBarycentric(barycentric, NumericT<T>::weakEps()));
299 
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]));
303 }
304 
305 template <typename T>
306 inline bool TriangleT3<T>::hasIntersection(const LineT3<T>& ray) const
307 {
308  ocean_assert(ray.isValid());
309 
310  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
311 
312  if (!matrix.invert())
313  {
314  return false;
315  }
316 
317  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
318 
319  return result.x() >= -NumericT<T>::eps() && result.y() >= -NumericT<T>::eps() && result.x() + result.y() <= T(1) + NumericT<T>::eps();
320 }
321 
322 template <typename T>
323 bool TriangleT3<T>::intersection(const LineT3<T>& ray, VectorT3<T>& point, T& distance) const
324 {
325  ocean_assert(ray.isValid());
326 
327  // following matrix multiplication determines the intersection of triangle plane P (with V0, V1, V2) and ray line L:
328  // L(r) = P(s,t)
329  // [V1-V0 V2-V0 -Ld] * [s t r] = [Lp-V0]
330  // L(r) is in triangle, when s>=0, t>=0 and s+t <= 1
331 
332  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
333 
334  if (!matrix.invert())
335  {
336  return false;
337  }
338 
339  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
340 
341  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
342  {
343  return false;
344  }
345 
346  distance = result.z();
347  point = ray.point() + ray.direction() * result.z();
348 
349  return true;
350 }
351 
352 template <typename T>
353 bool TriangleT3<T>::intersection(const LineT3<T>& ray, VectorT3<T>& point, VectorT3<T>& barycentric, T& distance) const
354 {
355  ocean_assert(ray.isValid());
356 
357  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
358 
359  if (!matrix.invert())
360  {
361  return false;
362  }
363 
364  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
365 
366  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
367  {
368  return false;
369  }
370 
371  distance = result.z();
372  point = ray.point() + ray.direction() * result.z();
373  barycentric = VectorT3<T>(1 - result.x() - result.y(), result.x(), result.y());
374 
375  return true;
376 }
377 
378 template <typename T>
379 bool TriangleT3<T>::intersection(const LineT3<T>& ray, LineT3<T>& reflection, T& distance) const
380 {
381  ocean_assert(ray.isValid());
382 
383  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
384 
385  if (!matrix.invert())
386  {
387  return false;
388  }
389 
390  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
391 
392  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
393  {
394  return false;
395  }
396 
397  distance = result.z();
398 
399  const VectorT3<T> normal((trianglePoints[1] - trianglePoints[0]).cross(trianglePoints[2] - trianglePoints[0]));
400  ocean_assert(NumericT<T>::isNotEqualEps(normal.length()));
401 
402  ocean_assert(NumericT<T>::isEqual(ray.direction().length(), 1));
403 
404  reflection = LineT3<T>(ray.point() + ray.direction() * result.z(), (-ray.direction()).reflect(normal));
405  ocean_assert(reflection.isValid());
406 
407  return true;
408 }
409 
410 template <typename T>
411 bool TriangleT3<T>::intersection(const LineT3<T>& ray, LineT3<T>& reflection, T& distance, VectorT3<T>& normal) const
412 {
413  ocean_assert(ray.isValid());
414 
415  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
416 
417  if (!matrix.invert())
418  {
419  return false;
420  }
421 
422  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
423 
424  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
425  {
426  return false;
427  }
428 
429  distance = result.z();
430 
431  normal = VectorT3<T>((trianglePoints[1] - trianglePoints[0]).cross(trianglePoints[2] - trianglePoints[0]));
432  ocean_assert(NumericT<T>::isNotEqualEps(normal.length()));
433 
434  ocean_assert(NumericT<T>::isEqual(ray.direction().length(), 1));
435 
436  reflection = LineT3<T>(ray.point() + ray.direction() * result.z(), (-ray.direction()).reflect(normal));
437  ocean_assert(reflection.isValid());
438 
439  return true;
440 }
441 
442 template <typename T>
443 inline bool TriangleT3<T>::frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal, LineT3<T>& reflection, T& distance) const
444 {
445  if (normal * ray.direction() > 0)
446  {
447  return false;
448  }
449 
450  ocean_assert(ray.isValid());
451  ocean_assert(NumericT<T>::isNotEqualEps(normal.length()));
452 
453  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
454 
455  if (!matrix.invert())
456  {
457  return false;
458  }
459 
460  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
461 
462  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
463  {
464  return false;
465  }
466 
467  distance = result.z();
468 
469  ocean_assert(NumericT<T>::isEqual(ray.direction().length(), 1));
470 
471  reflection = LineT3<T>(ray.point() + ray.direction() * result.z(), (-ray.direction()).reflect(normal));
472  ocean_assert(reflection.isValid());
473 
474  return true;
475 }
476 
477 template <typename T>
478 inline bool TriangleT3<T>::frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal0, const VectorT3<T>& normal1, const VectorT3<T>& normal2, LineT3<T>& reflection, T& distance) const
479 {
480  ocean_assert(ray.isValid());
481 
482  ocean_assert(NumericT<T>::isNotEqualEps(normal0.length()));
483  ocean_assert(NumericT<T>::isNotEqualEps(normal1.length()));
484  ocean_assert(NumericT<T>::isNotEqualEps(normal2.length()));
485 
486  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
487 
488  if (!matrix.invert())
489  {
490  return false;
491  }
492 
493  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
494 
495  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
496  {
497  return false;
498  }
499 
500  distance = result.z();
501 
502  const VectorT3<T> normal(normal0 * (1 - result.x() - result.y()) + normal1 * result.x() + normal2 * result.y());
503  ocean_assert(NumericT<T>::isNotEqualEps(normal.length()));
504 
505  ocean_assert(NumericT<T>::isEqual(ray.direction().length(), 1));
506 
507  if (normal * ray.direction() > 0)
508  {
509  return false;
510  }
511 
512  reflection = LineT3<T>(ray.point() + ray.direction() * result.z(), (-ray.direction()).reflect(normal));
513  ocean_assert(reflection.isValid());
514 
515  return true;
516 }
517 
518 template <typename T>
519 inline bool TriangleT3<T>::frontIntersection(const LineT3<T>& ray, const VectorT3<T>& normal0, const VectorT3<T>& normal1, const VectorT3<T>& normal2, LineT3<T>& reflection, T& distance, VectorT3<T>& normal) const
520 {
521  ocean_assert(ray.isValid());
522 
523  ocean_assert(NumericT<T>::isNotEqualEps(normal0.length()));
524  ocean_assert(NumericT<T>::isNotEqualEps(normal1.length()));
525  ocean_assert(NumericT<T>::isNotEqualEps(normal2.length()));
526 
527  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
528 
529  if (!matrix.invert())
530  {
531  return false;
532  }
533 
534  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
535 
536  if (result.x() < 0 || result.y() < 0 || result.x() + result.y() > 1)
537  {
538  return false;
539  }
540 
541  distance = result.z();
542 
543  normal = VectorT3<T>(normal0 * (1 - result.x() - result.y()) + normal1 * result.x() + normal2 * result.y());
544  ocean_assert(NumericT<T>::isNotEqualEps(normal.length()));
545  normal.normalize();
546 
547  ocean_assert(NumericT<T>::isEqual(ray.direction().length(), 1));
548 
549  if (normal * ray.direction() > 0)
550  {
551  return false;
552  }
553 
554  reflection = LineT3<T>(ray.point() + ray.direction() * result.z(), (-ray.direction()).reflect(normal));
555  ocean_assert(reflection.isValid());
556 
557  return true;
558 }
559 
560 template <typename T>
561 bool TriangleT3<T>::planeIntersection(const LineT3<T>& ray, VectorT3<T>& barycentric) const
562 {
563  ocean_assert(ray.isValid());
564 
565  SquareMatrixT3<T> matrix(trianglePoints[1] - trianglePoints[0], trianglePoints[2] - trianglePoints[0], -ray.direction());
566 
567  if (!matrix.invert())
568  {
569  return false;
570  }
571 
572  const VectorT3<T> result(matrix * (ray.point() - trianglePoints[0]));
573 
574  barycentric = VectorT3<T>(1 - result.x() - result.y(), result.x(), result.y());
575 
576  return true;
577 }
578 
579 template <typename T>
580 inline bool TriangleT3<T>::isValid() const
581 {
582  return trianglePoints[0] != trianglePoints[1] && trianglePoints[0] != trianglePoints[2] && trianglePoints[1] != trianglePoints[2];
583 }
584 
585 template <typename T>
586 inline const VectorT3<T>& TriangleT3<T>::operator[](const unsigned int index) const
587 {
588  ocean_assert(index <= 2u);
589  return trianglePoints[index];
590 }
591 
592 template <typename T>
594 {
595  return TriangleT3<T>(trianglePoints[0] + offset, trianglePoints[1] + offset, trianglePoints[2] + offset);
596 }
597 
598 template <typename T>
600 {
601  trianglePoints[0] += offset;
602  trianglePoints[1] += offset;
603  trianglePoints[2] += offset;
604 
605  return *this;
606 }
607 
608 template <typename T>
610 {
611  return TriangleT3<T>(trianglePoints[0] - offset, trianglePoints[1] - offset, trianglePoints[2] - offset);
612 }
613 
614 template <typename T>
616 {
617  trianglePoints[0] -= offset;
618  trianglePoints[1] -= offset;
619  trianglePoints[2] -= offset;
620 
621  return *this;
622 }
623 
624 }
625 
626 #endif // META_OCEAN_MATH_TRIANGLE_3_H
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