This section describes a function to compute a minimal enclosing strip (not necessarily axis-parallel) of a given convex point set. Note that this strip is not unique in general. A strip is the closed region bounded by two parallel lines in the plane.
#include <CGAL/minimum_enclosing_quadrilateral_2.h>
| ||||||
|
|
computes a minimum enclosing strip of the point set described by
[points_begin, points_end), writes its bounding lines to
o and returns the past-the-end iterator of this sequence.
If the input range is empty or consists of one element only, o
remains unchanged.
#include <CGAL/Cartesian.h> #include <CGAL/Point_2.h> #include <CGAL/Polygon_2.h> #include <CGAL/point_generators_2.h> #include <CGAL/random_convex_set_2.h> #include <CGAL/minimum_enclosing_quadrilateral_2.h> #include <vector> #include <iostream> using CGAL::Random_points_in_square_2; using CGAL::random_convex_set_2; using CGAL::minimum_enclosing_strip_2; using std::back_inserter; using std::cout; using std::endl; typedef CGAL::Cartesian< double > R; typedef R::Point_2 Point_2; typedef R::Line_2 Line_2; typedef CGAL::Polygon_traits_2< R > P_traits; typedef std::vector< Point_2 > Cont; typedef CGAL::Polygon_2< P_traits, Cont > Polygon_2; typedef CGAL::Creator_uniform_2< double, Point_2 > Creator; typedef Random_points_in_square_2< Point_2, Creator > Point_generator; int main() { // build a random convex 20-gon p Polygon_2 p; random_convex_set_2(20, back_inserter(p), Point_generator(1.0)); cout << p << endl; // compute the minimal enclosing strip p_m of p Line_2 p_m[2]; minimum_enclosing_strip_2( p.vertices_begin(), p.vertices_end(), p_m); cout << p_m[0] << "\n" << p_m[1] << endl; return 0; }