Guigue2003_tri_tri_intersect.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2021 Vladimir S. FONOV <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/
  8. #pragma once
  9. #ifndef IGL_TRI_TRI_INTERSECT_H
  10. #define IGL_TRI_TRI_INTERSECT_H
  11. #include "igl_inline.h"
  12. #include <Eigen/Core>
  13. namespace igl {
  14. // Three-dimensional Triangle-Triangle overlap test
  15. // if triangles are co-planar
  16. //
  17. // Input:
  18. // p1,q1,r1 - vertices of the 1st triangle (3D)
  19. // p2,q2,r2 - vertices of the 2nd triangle (3D)
  20. //
  21. // Output:
  22. //
  23. // Return true if two triangles overlap
  24. template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
  25. typename DerivedP2,typename DerivedQ2,typename DerivedR2>
  26. IGL_INLINE bool tri_tri_overlap_test_3d(
  27. const Eigen::MatrixBase<DerivedP1> & p1,
  28. const Eigen::MatrixBase<DerivedQ1> & q1,
  29. const Eigen::MatrixBase<DerivedR1> & r1,
  30. const Eigen::MatrixBase<DerivedP2> & p2,
  31. const Eigen::MatrixBase<DerivedQ2> & q2,
  32. const Eigen::MatrixBase<DerivedR2> & r2);
  33. // Three-dimensional Triangle-Triangle Intersection Test
  34. // additionaly computes the segment of intersection of the two triangles if it exists.
  35. // coplanar returns whether the triangles are coplanar,
  36. // source and target are the endpoints of the line segment of intersection
  37. //
  38. // Input:
  39. // p1,q1,r1 - vertices of the 1st triangle (3D)
  40. // p2,q2,r2 - vertices of the 2nd triangle (3D)
  41. //
  42. // Output:
  43. // coplanar - flag if two triangles are coplanar
  44. // source - 1st point of intersection (if exists)
  45. // target - 2nd point in intersection (if exists)
  46. //
  47. // Return true if two triangles intersect
  48. template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
  49. typename DerivedP2,typename DerivedQ2,typename DerivedR2,
  50. typename DerivedS,typename DerivedT>
  51. IGL_INLINE bool tri_tri_intersection_test_3d(
  52. const Eigen::MatrixBase<DerivedP1> & p1, const Eigen::MatrixBase<DerivedQ1> & q1, const Eigen::MatrixBase<DerivedR1> & r1,
  53. const Eigen::MatrixBase<DerivedP2> & p2, const Eigen::MatrixBase<DerivedQ2> & q2, const Eigen::MatrixBase<DerivedR2> & r2,
  54. bool & coplanar,
  55. Eigen::MatrixBase<DerivedS> & source,
  56. Eigen::MatrixBase<DerivedT> & target );
  57. // Two dimensional Triangle-Triangle Overlap Test
  58. // Input:
  59. // p1,q1,r1 - vertices of the 1st triangle (2D)
  60. // p2,q2,r2 - vertices of the 2nd triangle (2D)
  61. //
  62. // Output:
  63. // Return true if two triangles overlap
  64. template <typename DerivedP1,typename DerivedQ1,typename DerivedR1,
  65. typename DerivedP2,typename DerivedQ2,typename DerivedR2>
  66. IGL_INLINE bool tri_tri_overlap_test_2d(
  67. const Eigen::MatrixBase<DerivedP1> &p1, const Eigen::MatrixBase<DerivedQ1> &q1, const Eigen::MatrixBase<DerivedR1> &r1,
  68. const Eigen::MatrixBase<DerivedP2> &p2, const Eigen::MatrixBase<DerivedQ2> &q2, const Eigen::MatrixBase<DerivedR2> &r2);
  69. };
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "Guigue2003_tri_tri_intersect.cpp"
  72. #endif
  73. #endif // IGL_TRI_TRI_INTERSECT_H