An object of the class Min_sphere_of_spheres_d<Traits> is a data structure that represents the unique sphere of smallest volume enclosing a finite set of spheres in -dimensional Euclidean space . For a set of spheres we denote by the smallest sphere that contains all spheres of ; we call the minsphere of . can be degenerate, i.e., Ø, if Ø and , if . Any sphere in may be degenerate, too, i.e., any sphere from may be a point. Also, may contain several copies of the same sphere.
An inclusion-minimal subset of with is called a support set for ; the spheres in are the support spheres. A support set has size at most , and all its spheres lie on the boundary of . (A sphere is said to lie on the boundary of a sphere , if is contained in and if their boundaries intersect.) In general, the support set is not unique.
The algorithm computes the center and the radius of , and finds a support set (which remains fixed until the next insert(), clear() or set() operation). We also provide a specialization of the algorithm for the case when the center coordinates and radii of the input spheres are floating-point numbers. This specialized algorithm uses floating-point arithmetic only, is very fast and especially tuned for stability and robustness. Still, it's output may be incorrect in some (rare) cases; termination is guaranteed.
When default constructed, an instance of type Min_sphere_of_spheres_d<Traits> represents the set , together with its minsphere . You can add spheres to the set by calling insert(). Querying the minsphere is done by calling the routines is_empty(), radius() and center_cartesian_begin(), among others.
In general, the radius and the Euclidean center coordinates of need not be rational. Consequently, the algorithm computing the exact minsphere will have to deal with algebraic numbers. Fortunately, both the radius and the coordinates of the minsphere are numbers of the form , where and where is the same for all coordinates and the radius. Thus, the exact minsphere can be described by the number , which is called the sphere's discriminant, and by pairs (one for the radius and for the center coordinates).
#include <CGAL/Min_sphere_of_spheres_d.h>
Note: This class (almost) replaces CGAL::Min_sphere_d<Traits>, which solves the less general problem of finding the smallest enclosing ball of a set of points. Min_sphere_of_spheres_d<Traits> is faster than CGAL::Min_sphere_d<Traits>, and in contrast to the latter provides a specialized implementation for floating-point arithmetic which ensures correct results in a large number of cases (including highly degenerate ones). The only advantage of CGAL::Min_sphere_d<Traits> over Min_sphere_of_spheres_d<Traits> is that the former can deal with points in homogeneous coordinates, in which case the algorithm is division-free. Thus, CGAL::Min_sphere_d<Traits> might still be an option in case your input number type cannot (efficiently) divide.
The class Min_sphere_of_spheres_d<Traits> expects a model of the concept MinSphereOfSpheresTraits as its template argument.
| |
is a typedef to Traits::Sphere.
| |
| |
is a typedef to Traits::FT.
| |
| |
is the type of the radius and of the center
coordinates of the computed minsphere: When FT is an inexact
number type (double, for instance), then Result is
simply FT. However, when FT is an exact number type,
then Result is a typedef to a derived class of
std::pair<FT,FT>; an instance of this type represents the
number , where is the first and the second
element of the pair and where the number is accessed using the
member function disciminant() of class
Min_sphere_of_spheres_d<Traits>.
| |
| |
is either CGAL::LP_algorithm or
CGAL::Farthest_first_heuristic. As is described in the
documentation of concept MinSphereOfSpheresTraits, the type
Algorithm reflects the method which is used to compute the
minsphere. (Normally, Algorithm coincides with
Traits::Algorithm. However, if the method
Traits::Algorithm should not be supported anymore in a future
release, then Algorithm will have another type.)
| |
| |
non-mutable model of the STL
concept
BidirectionalIterator
with value type Sphere. Used
to access the support spheres defining the smallest enclosing sphere.
| |
| |
non-mutable model of the STL
concept
BidirectionalIterator
to access the center coordinates of the minsphere.
|
| |||
creates a variable of type Min_sphere_of_spheres_d<Traits> and initializes it to
Ø. If the traits
parameter is not supplied, the class Traits must provide a
default constructor.
| |||
| |||
| |||
creates a variable minsphere of type
Min_sphere_of_spheres_d<Traits> and inserts (cf.
insert()) the spheres from
the range [first,last).
|
|
| returns true, iff minsphere is empty, i.e. iff . |
|
| resets minsphere to Ø, with . | ||
| ||||
|
| |||
sets minsphere to
the , where is the set of spheres in the range
[first,last).
| ||||
|
| inserts the sphere s into the set of instance minsphere. | ||
| ||||
|
| |||
inserts the spheres in
the range [first,last) into the set of instance
minsphere.
|
|
| returns true, iff minsphere is valid. When FT is inexact, this routine always returns true. |
|
| returns a const reference to the traits class object. |
We implement two algorithms, the LP-algorithm and a heuristic [MSW92]. As described in the documentation of concept MinSphereOfSpheresTraits, each has its advantages and disadvantages: Our implementation of the LP-algorithm has maximal expected running time , while the heuristic comes without any complexity guarantee. In particular, the LP-algorithm runs in linear time for fixed dimension . (These running times hold for the arithmetic model, so they count the number of operations on the number type FT.)
On the other hand, the LP-algorithm is, for inexact number types FT, much worse at handling degeneracies and should therefore not be used in such a case. (For exact number types FT, both methods handle all kinds of degeneracies.)
Currently, we require Traits::FT to be either an exact number type or double or float; other inexact number types are not supported at this time. Also, the current implementation only handles spheres with Cartesian coordinates; homogenous representation is not supported yet.
File: examples/Min_sphere_of_spheres_d/min_sphere_of_spheres_d_d.cpp
#include <CGAL/Cartesian_d.h> #include <CGAL/Random.h> #include <CGAL/Gmpq.h> #include <CGAL/Min_sphere_of_spheres_d.h> #include <vector> const int N = 1000; // number of spheres const int D = 3; // dimension of points const int LOW = 0, HIGH = 10000; // range of coordinates and radii typedef CGAL::Gmpq FT; //typedef double FT; typedef CGAL::Cartesian_d<FT> K; typedef CGAL::Min_sphere_of_spheres_d_traits_d<K,FT,D> Traits; typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere; typedef K::Point_d Point; typedef Traits::Sphere Sphere; int main () { std::vector<Sphere> S; // n spheres FT 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_int(LOW,HIGH); Point p(D,coord,coord+D); // random center... S.push_back(Sphere(p,r.get_int(LOW,HIGH))); // ...and random radius } Min_sphere ms(S.begin(),S.end()); // check in the spheres CGAL_assertion(ms.is_valid()); }