![]() |
The function random_polygon_2constructs a random simple polygon from points that are drawn from a specific domain. Though each simple polygon defined on this set of points has a non-zero probability of being constructed, some polygons may have higher probabilities than others. The overall distribution of the generated polygons is not known since it depends on the generated points.
#include <CGAL/random_polygon_2.h>
|
| ||||
|
|
| |||
| computes a random simple polygon by writing its vertices (oriented counterclockwise) to result. The polygon generated will have a number of vertices equal to the number of unique points in the first points generated by pg. | ||||
The default traits class Default_traits is the kernel in which Traits::Point_2 is defined.
The following program displays a random simple polygon with up to 50 vertices, where the vertex coordinates are drawn uniformly from the unit square centered at the origin.
// file: examples/Generator/random_poly_example.C
#include <CGAL/Cartesian.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/random_polygon_2.h>
#include <CGAL/Polygon_2.h>
typedef CGAL::Cartesian< double > K;
typedef K::Point_2 Point_2;
typedef std::list<Point_2> Container;
typedef CGAL::Polygon_2<K, Container> Polygon_2;
typedef CGAL::Random_points_in_square_2< Point_2 > Point_generator;
int main() {
Polygon_2 polygon;
// create 50-gon and write it into a window:
CGAL::random_polygon_2(50, std::back_inserter(polygon),
Point_generator(0.5));
std::cout << polygon;
return 0;
}