CGAL 6.1.2 - 3D Spherical Geometry Kernel

Loading...
Searching...
No Matches
Circular_kernel_3/intersecting_spheres.cpp
#include <CGAL/Exact_spherical_kernel_3.h>
#include <CGAL/Random.h>
typedef CGAL::Exact_spherical_kernel_3 SK;
typedef CGAL::Point_3<SK> Point_3;
typedef CGAL::Sphere_3<SK> Sphere_3;
typedef CGAL::Circle_3<SK> Circle_3;
typedef CGAL::Circular_arc_point_3<SK> Circular_arc_point_3;
int main() {
CGAL::Random generatorOfgenerator;
int random_seed = generatorOfgenerator.get_int(0, 123456);
CGAL::Random theRandom(random_seed);
int count = 0;
std::cout << "We will compute the approximate probability that 3 spheres with"
<< " radius 1 intersect on a 5x5x5 box, it might take some time." << std::endl;
for(int i=0; i<10000; i++) {
double x1 = theRandom.get_double(0.0,5.0);
double y1 = theRandom.get_double(0.0,5.0);
double z1 = theRandom.get_double(0.0,5.0);
double r = 1.0;
double x2 = theRandom.get_double(0.0,5.0);
double y2 = theRandom.get_double(0.0,5.0);
double z2 = theRandom.get_double(0.0,5.0);
double x3 = theRandom.get_double(0.0,5.0);
double y3 = theRandom.get_double(0.0,5.0);
double z3 = theRandom.get_double(0.0,5.0);
Sphere_3 s1 = Sphere_3(Point_3(x1,y1,z1), r);
Sphere_3 s2 = Sphere_3(Point_3(x2,y2,z2), r);
Sphere_3 s3 = Sphere_3(Point_3(x3,y3,z3), r);
std::vector< std::variant<Sphere_3, Circle_3, std::pair<Circular_arc_point_3, unsigned> > > intersecs;
CGAL::intersection(s1, s2, s3, std::back_inserter(intersecs));
if(intersecs.size() > 0) ++count;
}
std::cout << "The approximate probability that 3 spheres with radius 1"
<< std::endl;
std::cout << "chosen (uniformly) randomly on a 5x5x5 box intersect is: "
<< (static_cast<double>(count))/(static_cast<double>(10000)) << std::endl;
return 0;
}
CGAL::Circle_3
CGAL::Circular_arc_point_3
Definition: Circular_arc_point_3.h:14
CGAL::Exact_spherical_kernel_3
A typedef to a spherical kernel that provides both exact geometric predicates and exact geometric con...
Definition: Exact_spherical_kernel_3.h:16
CGAL::Point_3
CGAL::Sphere_3
CGAL::intersection
decltype(auto) intersection(Type1< Kernel > obj1, Type2< Kernel > obj2)