File: random_points_triangle_2.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (35 lines) | stat: -rw-r--r-- 1,411 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Random.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel                 K;
typedef K::Point_2                                                                                                         Point_2;
typedef K::Triangle_2                                                                                                 Triangle_2;
typedef std::vector<Point_2>                                                                                Container;
typedef CGAL::Random_points_in_triangle_2<Point_2>                                         Point_generator;

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;
}