\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 5.0.4 - Geometric Object Generators
Generator/random_points_triangle_2.cpp
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Random.h>
typedef K::Point_2 Point_2;
typedef K::Triangle_2 Triangle_2;
typedef std::vector<Point_2> Container;
int main() {
std::cout << "Creating 100 random points in a triangle in 2D." << std::endl;
// The input triangle is as follows
Triangle_2 tri(Point_2(0,0),Point_2(1,0),Point_2(0,1));
// generated points are in that container
Container points;
// creating the generator, input is the Triangle_2 tri
Point_generator g(tri);
// get 100 random points in tri
std::copy_n(g, 100, std::back_inserter(points));
// Check that we have really created 100 points.
assert( points.size() == 100);
// print the first point that was generated
std::cout << points[0] << std::endl;
return 0;
}