An object of the class Min_ellipse_2<Traits> is the unique ellipse of smallest area enclosing a finite (multi)set of points in two-dimensional euclidean space . For a point set we denote by the smallest ellipse that contains all points of . Note that can be degenerate, i.e. Ø if Ø, if , and (1-l)p + l q | 0 <= l <= 1 if .
An inclusion-minimal subset of with is called a support set, the points in are the support points. A support set has size at most five, and all its points lie on the boundary of . In general, neither the support set nor its size are necessarily unique.
The underlying algorithm can cope with all kinds of input, e.g. may be empty or points may occur more than once. The algorithm computes a support set which remains fixed until the next insert or clear operation.
#include <CGAL/Min_ellipse_2.h>
The template parameter Traits is a model for MinEllipse2Traits.
We provide the model CGAL::Min_ellipse_2_traits_2<K> using the two-dimensional CGAL kernel.
| |
Typedef to Traits::Point .
| |
| |
Typedef to Traits::Ellipse. If you
are using the predefined traits class
CGAL::Min_ellipse_2_traits_2<K>,
you can access the coefficients of the ellipse, see the
documentation of CGAL::Min_ellipse_2_traits_2<K> and
the example below.
| |
| |
Non-mutable model of the STL concept BidirectionalIterator
with value type Point. Used to access the points
of the smallest enclosing ellipse.
| |
| |
Non-mutable model of the STL concept RandomAccessIterator
with value type Point. Used to access the support points
of the smallest enclosing ellipse.
|
A Min_ellipse_2<Traits> object can be created from an arbitrary point set and by specialized construction methods expecting no, one, two, three, four or five points as arguments. The latter methods can be useful for reconstructing from a given support set of .
| |||
| |||
initializes min_ellipse to with being the set of points
in the range [first,last). If randomize is
true, a random permutation of is computed in
advance, using the random numbers generator random.
Usually, this will not be necessary, however, the algorithm's
efficiency depends on the order in which the points are
processed, and a bad order might lead to extremely poor
performance (see example below). Requirement: The value type of first and last is Point.
| |||
| |||
creates a variable min_ellipse of type Min_ellipse_2<Traits>.
It is initialized to
Ø, the empty set. Postcondition: min_ellipse.is_empty() = true.
| |||
| |||
initializes min_ellipse to , the set . Postcondition: min_ellipse.is_degenerate() = true.
| |||
| |||
initializes min_ellipse to ,
the set
(1-l)p + l q | 0 <= l <= 1. Postcondition: min_ellipse.is_degenerate() = true.
| |||
| |||
initializes min_ellipse to .
| |||
| |||
initializes min_ellipse to .
| |||
| |||
initializes min_ellipse to .
|
By definition, an empty Min_ellipse_2<Traits> has no boundary and no bounded side, i.e. its unbounded side equals the whole space .
|
| |
returns CGAL::ON_BOUNDED_SIDE, CGAL::ON_BOUNDARY, or CGAL::ON_UNBOUNDED_SIDE iff p lies properly inside, on the boundary of, or properly outside of min_ellipse, resp. | ||
|
| |
returns true, iff p lies properly inside min_ellipse. | ||
|
| |
returns true, iff p lies on the boundary of min_ellipse. | ||
|
| |
returns true, iff p lies properly outside of min_ellipse. | ||
|
| |
returns true, iff min_ellipse is empty (this implies degeneracy). | ||
|
| |
returns true, iff min_ellipse is degenerate, i.e. if min_ellipse is empty, equal to a single point or equal to a segment, equivalently if the number of support points is less than 3. |
New points can be added to an existing min_ellipse, allowing to build incrementally, e.g. if is not known in advance. Compared to the direct creation of , this is not much slower, because the construction method is incremental itself.
An object min_ellipse is valid, iff
|
| |||
returns true, iff min_ellipse contains all points of its defining set . If verbose is true, some messages concerning the performed checks are written to standard error stream. The second parameter level is not used, we provide it only for consistency with interfaces of other classes. |
|
| |
returns a const reference to the traits class object. |
|
| |
writes min_ellipse to output stream os. Requirement: The output operator is defined for Point (and for Ellipse, if pretty printing is used). |
|
| |
reads min_ellipse from input stream is. Requirement: The input operator is defined for Point. |
#include <CGAL/IO/Window_stream.h>
| ||
| ||
writes min_ellipse to window stream ws. Requirement: The window stream output operator is defined for Point and Ellipse. |
CGAL::Min_circle_2<Traits>
CGAL::Min_ellipse_2_traits_2<K>
MinEllipse2Traits
We implement the incremental algorithm of Welzl, with move-to-front heuristic [Wel91], using the primitives as described in [GS97a, GS97b]. The whole implementation is described in [GS98b].
If randomization is chosen, the creation time is almost always linear in the number of points. Access functions and predicates take constant time, inserting a point might take up to linear time, but substantially less than computing the new smallest enclosing ellipse from scratch. The clear operation and the check for validity each takes linear time.
To illustrate the usage of Min_ellipse_2<Traits> and to show that randomization can be useful in certain cases, we give an example. The example also shows how the coefficents of the constructed ellipse can be accessed.
// file: examples/Min_ellipse_2/example_Min_ellipse_2.C // includes #include <cassert> #include <CGAL/Cartesian.h> #include <CGAL/Point_2.h> #include <CGAL/Min_ellipse_2.h> #include <CGAL/Min_ellipse_2_traits_2.h> #include <CGAL/Gmpq.h> // typedefs typedef CGAL::Gmpq NT; typedef CGAL::Cartesian<NT> K; typedef CGAL::Point_2<K> Point; typedef CGAL::Min_ellipse_2_traits_2<K> Traits; typedef CGAL::Min_ellipse_2<Traits> Min_ellipse; // main int main( int, char**) { int n = 200; Point* P = new Point[ n]; for ( int i = 0; i < n; ++i) P[ i] = Point( i % 2 ? i : -i , 0); // (0,0), (-1,0), (2,0), (-3,0) std::cout << "Computing ellipse (without randomization)..."; std::cout.flush(); Min_ellipse me1( P, P+n, false); // very slow std::cout << "done." << std::endl; std::cout << "Computing ellipse (with randomization)..."; std::cout.flush(); Min_ellipse me2( P, P+n, true); // fast std::cout << "done." << std::endl; // because all input points are collinear, the ellipse is // degenerate and equals a line segment; the ellipse has // two support points assert(me2.is_degenerate()); assert(me2.number_of_support_points()==2); // prettyprinting CGAL::set_pretty_mode( std::cout); std::cout << me2; // in general, the ellipse is not explicitly representable // over the input number type NT; when you use the default // traits class CGAL::Min_ellipse_2_traits_2<K>, you can // get double approximations for the coefficients of the // underlying conic curve. NOTE: this curve only exists // in the nondegenerate case! me2.insert(Point(0,1)); // resolves the degeneracy assert(!me2.is_degenerate()); // get the coefficients double r,s,t,u,v,w; me2.ellipse().double_coefficients( r, s, t, u, v, w); std::cout << "ellipse has the equation " << r << " x^2 + " << s << " y^2 + " << t << " xy + " << u << " x + " << v << " y + " << w << " = 0." << std::endl; delete[] P; return( 0); } // ===== EOF ==================================================================