![]() |
#include <CGAL/extremal_polygon_2.h>
|
| ||||||
|
|
| |||||
computes a maximum perimeter inscribed -gon of the convex polygon described by [points_begin, points_end), writes its vertices to o and returns the past-the-end iterator of this sequence.
Precondition:
Requirement:
#include <CGAL/Cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/random_convex_set_2.h>
#include <CGAL/extremal_polygon_2.h>
#include <iostream>
#include <vector>
typedef double FT;
struct Kernel : public CGAL::Cartesian<FT> {};
typedef Kernel::Point_2 Point;
typedef std::vector<int> Index_cont;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Random_points_in_square_2<Point> Generator;
int main() {
int n = 10;
int k = 5;
// generate random convex polygon:
Polygon p;
CGAL::random_convex_set_2(n, std::back_inserter(p), Generator(1));
std::cout << "Generated Polygon:\n" << p << std::endl;
// compute maximum perimeter incribed k-gon of p:
Polygon k_gon;
CGAL::maximum_perimeter_inscribed_k_gon_2(
p.vertices_begin(), p.vertices_end(), k, std::back_inserter(k_gon));
std::cout << "Maximum perimeter " << k << "-gon:\n"
<< k_gon << std::endl;
return 0;
}