Add examples that use the point traits

This commit is contained in:
Andreas Fabri 2020-08-21 09:12:24 +01:00
parent e22d0369ac
commit a571606269
5 changed files with 84 additions and 13 deletions

View File

@ -4,11 +4,13 @@
\example Min_annulus_d/min_annulus_d.cpp
\example Min_annulus_d/min_annulus_d_fast_exact.cpp
\example Min_circle_2/min_circle_2.cpp
\example Min_circle_2/min_circle_homogeneous_2.cpp
\example Min_ellipse_2/min_ellipse_2.cpp
\example Min_quadrilateral_2/minimum_enclosing_parallelogram_2.cpp
\example Min_quadrilateral_2/minimum_enclosing_rectangle_2.cpp
\example Min_quadrilateral_2/minimum_enclosing_strip_2.cpp
\example Min_sphere_d/min_sphere_d.cpp
\example Min_sphere_d/min_sphere_homogeneous_d.cpp
\example Min_sphere_of_spheres_d/benchmark.cpp
\example Min_sphere_of_spheres_d/min_sphere_of_spheres_d_2.cpp
\example Min_sphere_of_spheres_d/min_sphere_of_spheres_d_3.cpp

View File

@ -1,14 +1,15 @@
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Min_circle_2.h>
#include <CGAL/Min_circle_2_traits_2.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Min_sphere_of_spheres_d.h>
#include <CGAL/Min_sphere_of_points_d_traits_2.h.h>
#include <iostream>
// typedefs
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Min_circle_2_traits_2<K> Traits;
typedef CGAL::Min_circle_2<Traits> Min_circle;
typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_2<K> Traits;
typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_circle;
typedef K::Point_2 Point;
typedef K::Point_2 Point;
int
main( int, char**)
@ -16,15 +17,15 @@ main( int, char**)
const int n = 100;
Point P[n];
for ( int i = 0; i < n; ++i)
P[ i] = Point( (i%2 == 0 ? i : -i), 0);
// (0,0), (-1,0), (2,0), (-3,0), ...
for ( int i = 0; i < n; ++i){
P[ i] = Point( (i%2 == 0 ? i : -i), 0, 1);
// (0,0), (-1,0), (2,0), (-3,0), ...
}
Min_circle mc1( P, P+n, false); // very slow
Min_circle mc2( P, P+n, true); // fast
Min_circle mc( P, P+n);
CGAL::set_pretty_mode( std::cout);
std::cout << mc2;
std::cout << mc;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <CGAL/Exact_integer.h>
#include <CGAL/Simple_homogeneous.h>
#include <CGAL/Min_circle_2.h>
#include <CGAL/Min_circle_2_traits_2.h>
#include <iostream>
// typedefs
typedef CGAL::Exact_integer RT;
typedef CGAL::Simple_homogenous<RT> K;
typedef CGAL::Min_circle_2_traits_2<K> Traits;
typedef CGAL::Min_circle_2<Traits> Min_circle;
typedef K::Point_2 Point;
int
main( int, char**)
{
const int n = 100;
Point P[n];
for ( int i = 0; i < n; ++i){
P[ i] = Point( (i%2 == 0 ? i : -i), 0, 1);
// (0,0), (-1,0), (2,0), (-3,0), ...
}
Min_circle mc1( P, P+n, false); // very slow
Min_circle mc2( P, P+n, true); // fast
CGAL::set_pretty_mode( std::cout);
std::cout << mc2;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <CGAL/Simple_cartesian.h>
#include <iostream>
#include <cstdlib>
#include <CGAL/Random.h>
#include <CGAL/Min_sphere_of_points_d_traits_3.h>
#include <CGAL/Min_sphere_of_spheres_d.h>
typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_3<K> Traits;
typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere;
typedef K::Point_3 Point;
const int n = 10; // number of points
const int d = 3; // dimension of points
int main ()
{
Point P[n]; // n points
double coord[d]; // d coordinates
CGAL::Random r; // random number generator
for (int i=0; i<n; ++i) {
for (int j=0; j<d; ++j)
coord[j] = r.get_double();
P[i] = Point(d, coord, coord+d); // random point
}
Min_sphere ms (P, P+n); // smallest enclosing sphere
CGAL::set_pretty_mode (std::cout);
std::cout << ms; // output the sphere
return 0;
}