tri_tri_intersect.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "test_common.h"
  2. #include <igl/tri_tri_intersect.h>
  3. TEST_CASE("tri_tri_intersection_test_3d intersect", "[igl]")
  4. {
  5. // try with oblique interecion plane
  6. for(double shift=-1000;shift<=1000;shift+=100.0)
  7. {
  8. Eigen::RowVector3d p1(0,0,0), q1(1,0,0),r1(0,1,0);
  9. Eigen::RowVector3d p2(shift,0,1),q2(1,1,0),r2(-shift,0,-1);
  10. // should intersect along the vector (0,0,0) -> (0.5,0.5,0)
  11. Eigen::RowVector3d s,t;
  12. bool coplanar;
  13. REQUIRE( igl::tri_tri_intersection_test_3d(p1,q1,r1, p2,q2,r2, coplanar, s, t) );
  14. REQUIRE( !coplanar);
  15. if(s.norm()<1e-5)
  16. {
  17. Eigen::RowVector3d t_correct(0.5,0.5,0);
  18. Eigen::RowVector3d s_correct(0,0,0);
  19. test_common::assert_near( t, t_correct, 1e-10);
  20. test_common::assert_near( s, s_correct, 1e-10);
  21. } else {
  22. Eigen::RowVector3d s_correct(0.5,0.5,0);
  23. Eigen::RowVector3d t_correct(0,0,0);
  24. test_common::assert_near( t, t_correct, 1e-10);
  25. test_common::assert_near( s, s_correct, 1e-10);
  26. }
  27. }
  28. }
  29. TEST_CASE("tri_tri_intersection_test_3d not intersect", "[igl]")
  30. {
  31. // positive test that two triangles intersect
  32. Eigen::RowVector3d p1(0,0,0),q1(1,0,0),r1(0,1,0);
  33. Eigen::RowVector3d p2(0,0,1),q2(1,0,1),r2(0,1,1);
  34. // should intersect along the vector (0,0,0) -> (sqrt(2),sqrt(2),0)
  35. Eigen::RowVector3d s,t;
  36. bool coplanar;
  37. REQUIRE( !igl::tri_tri_intersection_test_3d(p1,q1,r1,p2,q2,r2, coplanar, s, t) );
  38. }
  39. TEST_CASE("tri_tri_intersection_test_3d coplanar", "[igl]")
  40. {
  41. // positive test that two triangles intersect
  42. Eigen::RowVector3d p1(0,0,0),q1(1,0,0),r1(0,1,0);
  43. Eigen::RowVector3d p2(0,0,0),q2(0.5,0,0),r2(0,0.5,0);
  44. // should intersect along the vector (0,0,0) -> (sqrt(2),sqrt(2),0)
  45. Eigen::RowVector3d s,t;
  46. bool coplanar;
  47. REQUIRE( igl::tri_tri_intersection_test_3d(p1,q1,r1,p2,q2,r2, coplanar, s, t) );
  48. REQUIRE(coplanar);
  49. }