Files
cgal/Bounding_volumes/examples/Min_annulus_d/min_annulus_d.cpp
T
Philipp Möller 394b8de4d9 Merge the Bounding_volumes package from its parts
Merge Min_circle_2, Min_ellipse_2, Min_sphere_d, Min_annulus_d,
Min_sphere_of_spheres_d, Min_quadrilateral_2 and
Approximate_min_ellipsoid_d. The documentation from the part that is
in Matrix_search has also been moved here, but not the code. Add a new
don't submit that covers the old ones, combine the package_info
files. Examples and tests are still in separate folders. Merge them in
a separate step.
2012-08-16 09:44:11 +00:00

57 lines
1.7 KiB
C++

// computes the smallest enclosing annulus of two point
// sets on nested squares in R^2, using double
// as input type and some internal EXACT floating point type
#include <iostream>
#include <cassert>
#include <CGAL/Homogeneous.h>
#include <CGAL/Min_annulus_d.h>
#include <CGAL/Min_sphere_annulus_d_traits_2.h>
#ifdef CGAL_USE_GMP
#include <CGAL/Gmpzf.h>
typedef CGAL::Gmpzf ET;
#else
#include <CGAL/MP_Float.h>
typedef CGAL::MP_Float ET;
#endif
// use an EXACT kernel...
typedef CGAL::Homogeneous<ET> K;
typedef K::Point_2 Point;
// ...and the traits class based on the exact kernel
typedef CGAL::Min_sphere_annulus_d_traits_2<K> Traits;
typedef CGAL::Min_annulus_d<Traits> Min_annulus;
int main()
{
// points on the squares [-1,1]^2 and [-2,2]^2
Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
Min_annulus ma(P, P+8);
assert (ma.is_valid());
// get center of annulus
Min_annulus::Coordinate_iterator coord_it;
std::cout << "center:"; // homogeneous point, (0,0,1)
for (coord_it = ma.center_coordinates_begin();
coord_it != ma.center_coordinates_end();
++coord_it)
std::cout << " " << *coord_it;
std::cout << std::endl;
// get inner squared radius, 1^2+1^2 = 2
std::cout << "Inner squared radius: " <<
CGAL::to_double(ma.squared_inner_radius_numerator()) /
CGAL::to_double(ma.squared_radii_denominator()) << std::endl;
// get outer squared radius, 2^2+2^2 = 8
std::cout << "Outer squared radius: " <<
CGAL::to_double(ma.squared_outer_radius_numerator()) /
CGAL::to_double(ma.squared_radii_denominator()) << std::endl;
return 0;
}