// 3D intersection tests. // We want to check that no division is performed for interface macro Do_intersect_3_RT #define CGAL_NO_MPZF_DIVISION_OPERATOR // Sphere_3_X with X < Sphere (lexicographically) are tested in other files #include #include #include #include #include #include #include "intersection_test_helper.h" #include #include #include #include #include #include #include template struct Ray_3_intersection_tester : public Intersection_3_tester { typedef Intersection_3_tester Base; typedef typename K::FT FT; typedef CGAL::Iso_cuboid_3 Cub; typedef CGAL::Line_3 L; typedef CGAL::Point_3 P; typedef CGAL::Plane_3 Pl; typedef CGAL::Ray_3 R; typedef CGAL::Segment_3 S; typedef CGAL::Sphere_3 Sph; typedef CGAL::Tetrahedron_3 Tet; typedef CGAL::Triangle_3 Tr; typedef CGAL::Vector_3 V; using Base::p; using Base::pl; using Base::random_point; using Base::check_do_intersect; using Base::check_do_not_intersect; using Base::check_intersection; using Base::check_no_intersection; private: int N = 1000; public: Ray_3_intersection_tester(CGAL::Random& r, const bool has_exact_p = false, const bool has_exact_c = false) : Base(r, has_exact_p, has_exact_c) { } public: void R_R() { std::cout << "Ray - Ray\n"; // No intersection check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(-2,0,0), p(-3,0,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-1,0), p(1,-2,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,-1,0), p(0,-2,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,1,0), p(0,2,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(-1,0,0), p(-1,-1,0))); check_no_intersection (R(p(1,-1,0), p(2,0,0)), R(p(2,-1,0), p(3,0,0))); check_no_intersection (R(p(1,-1,0), p(2,0,0)), R(p(2,-1,0), p(3,-1,0))); check_no_intersection (R(p(1,-1,0), p(2,0,0)), R(p(2,-1,0), p(3,-2,0))); check_no_intersection (R(p(0,0,0), p(0,1,0)), R(p(0,-1,0), p(1,-1,0))); check_no_intersection (R(p(0,0,0), p(0,1,0)), R(p(-1,-3,0),p(2,0,0))); check_no_intersection (R(p(0,0,0), p(0,1,0)), R(p(-2,-4,0),p(-1,-3,0))); check_no_intersection (R(p(0,0,0), p(0,1,0)), R(p(1,-1,0), p(2,0,0))); // Point check_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,0,0), p(-1,0,0)), p(0,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,0,0), p(0,1,0)), p(0,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(5,0,0), p(5,1,0)), p(5,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,0,0), p(1,1,0)), p(1,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-1,0), p(1,1,0)), p(1,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-2,0), p(1,-1,0)), p(1,0,0)); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-2,0), p(1,-1,0)), p(1,0,0)); // Segment check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(-3,0,0)), S(p(0,0,0), p(2,0,0)), false); check_intersection (R(p(2,0,0), p(-3,0,0)), R(p(0,0,0), p(1,0,0)), S(p(2,0,0), p(0,0,0)), false); // Ray check_intersection (R(p(0,0,0), p(1,0,0)), R(p(-1,0,0), p(3,0,0)), R(p(0,0,0), p(1,0,0))); check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(3,0,0)), R(p(2,0,0), p(6,0,0))); } void R_S() { std::cout << "Ray - Segment\n"; // No intersection check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-1,0), p(0,-2,0))); check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-1,0), p(-3,-2,0))); check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-1,0), p(3,-2,0))); check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(4,0,0), p(5,0,0))); check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-5,0,0), p(-8,0,0))); // Point check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-2,0), p(0,-1,0)), p(0,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-2,0), p(-3,-1,0)), p(-3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-2,0), p(3,-1,0)), p(3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(0,-1,0)), p(0,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-3,-1,0)), p(-3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,0,0), p(3,-1,0)), p(3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-2,0), p(0,0,0)), p(0,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-2,0), p(-3,0,0)), p(-3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-2,0), p(3,0,0)), p(3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-4,0,0)), p(-3,0,0)); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,0,0), p(4,0,0)), p(3,0,0)); // Segment check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-4,0,0), p(-2,0,0)), S(p(-3,0,0), p(3,0,0))); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-4,0,0), p(7,0,0)), S(p(-3,0,0), p(3,0,0))); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-2,0,0)), S(p(-3,0,0), p(3,0,0))); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(7,0,0)), S(p(-3,0,0), p(3,0,0))); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(-2,0,0)), S(p(0,0,0), p(-3,0,0))); check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(2,0,0)), S(p(0,0,0), p(3,0,0))); } void R_Sph() { std::cout << "Ray - Sphere\n"; // No intersection check_do_not_intersect(R(p(0,1,7), p(1,2,1)), Sph(p(0,8,4), 4)); for(int i=0; ihas_exact_c) { Pl pln(q, V(c, q)); // plane tangent to the sphere at q V v1 = pln.base1(); check_do_intersect(R(q, q + v1), sph); } // maybe two points P r = random_point(); if(q == r) continue; check_do_intersect(R(q, r), sph); } } void R_Tet() { std::cout << "Ray - Tetrahedron\n"; Tet tet(p(0,0,0), p(0,1,0), p(1,0,0), p(0,0,1)); check_no_intersection (R(p(5,0,0), p(5,1,0)), tet); check_intersection (R(p(0,2,0), p(0,-2,0)), tet, S(p(0,1,0), p(0,0,0))); check_intersection (R(p(0,1,0), P(0.25,0,0.25)), tet, S(p(0,1,0), P(0.25,0,0.25))); check_intersection (R(p(2,1,0), p(-2,1,0)), tet, p(0,1,0)); typename K::FT third = FT(1)/FT(3); typename K::FT fifth = FT(1)/FT(5); typename K::FT tenth = FT(1)/FT(10); if(this->has_exact_c) { check_intersection (tet, R(P(tenth,tenth,tenth), P(fifth,fifth,fifth)), S(P(tenth,tenth,tenth), P(third, third, third))); check_intersection (tet, R(P(0.25,0.25,0.25), p(2,2,2)), S(P(0.25,0.25,0.25), P(third, third, third))); } else { CGAL::intersection(tet, R(p(0,2,0), p(0,-2,0))); CGAL::intersection(tet, R(p(0,1,0), P(0.25,0,0.25))); CGAL::intersection(tet, R(p(2,1,0), p(-2,1,0))); CGAL::intersection(tet, R(P(tenth,tenth,tenth), P(fifth,fifth,fifth))); CGAL::intersection(tet, R(P(0.25,0.25,0.25), p(2,2,2))); } } void R_Tr() { std::cout << "Ray - Triangle\n"; check_no_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(-4, 2, 2), p(3, 7, -1), p(0, 9, -4))); check_no_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(-1, -1, -1), p(3, 7, -1), p(0, 9, -4))); // Point check_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(0, 0, 0), p(3, 7, -1), p(0, 9, -4)), p(0, 0, 0)); check_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(2, 2, 2), p(3, 7, -1), p(0, 9, -4)), p(2, 2, 2)); check_intersection(R(p(0,0,0), p(4,-2,6)), Tr(p(2, -1, 3), p(3, 7, -1), p(0, 9, -4)), p(2, -1, 3)); check_intersection(R(p(0,0,0), p(2,-1,3)), Tr(p(4, -2, 6), p(3, 7, -2), p(0, 8, -4)), p(4, -2, 6)); Base::template check_intersection

(R(p(0,0,0), p(1,1,1)), Tr(p(2, 4, 2), p(5, -7, -1), p(0, -9, 4))); // Segment check_intersection(R(p(0,0,1), p(1,1,1)), Tr(p(3, 3, 1), p(7, 7, 1), p(0, -9, -4)), S(p(3, 3, 1), p(7,7,1))); check_intersection(R(p(0,0,1), p(1,1,1)), Tr(p(7, 7, 1), p(3, 3, 1), p(0, -9, -4)), S(p(3, 3, 1), p(7,7,1))); check_intersection(R(p(3,3,1), p(7,7,1)), Tr(p(4, 4, 1), p(2, 2, 1), p(0, -9, -4)), S(p(3, 3, 1), p(4,4,1))); } void run() { std::cout << "3D Ray Intersection tests\n"; R_R(); R_S(); R_Sph(); R_Tet(); R_Tr(); } }; int main(int, char**) { std::cout.precision(17); std::cerr.precision(17); CGAL::Random r; std::cout << "random seed = " << r.get_seed() << std::endl; std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; Ray_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; Ray_3_intersection_tester< CGAL::Homogeneous >(r).run(); std::cout << " |||||||| Test EPICK ||||||||" << std::endl; Ray_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); std::cout << " |||||||| Test EPECK ||||||||" << std::endl; Ray_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; Ray_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); std::cout << "OK!" << std::endl; }