File: random_points_tetrahedron_and_triangle_3.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (49 lines) | stat: -rw-r--r-- 2,265 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/Random.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel                 K;
typedef K::Point_3                                                                                                         Point_3;
typedef K::Triangle_3                                                                                                 Triangle_3;
typedef K::Tetrahedron_3                                                                                         Tetrahedron_3;
typedef CGAL::Random_points_in_triangle_3<Point_3>                                         Point_generator_i;
typedef CGAL::Random_points_in_tetrahedron_3<Point_3>                                 Point_generator_ii;

int main() {
        std::cout << "This example does two things:" << std::endl;
        std::cout << "  (i) it creates 100 random points in a triangle in 3D; and" << std::endl;
        std::cout << "  (ii) it creates 100 random points in a tetrahedron in 3D." << std::endl;

        // The input triangle is as follows
        Triangle_3 tri(Point_3(0,0,0),Point_3(1,0,0),Point_3(0,1,0));
        Tetrahedron_3 tet(Point_3(0,0,0),Point_3(1,0,0),Point_3(0,1,0),Point_3(0,0,1));

        // we get output points in these containers
        std::vector<Point_3> points_in_tri, points_in_tet;

        // creating the first generator, input is the Triangle_3 tri
        Point_generator_i g_i(tri);

        // creating the second generator, input is the Tetrahedron_3 tet
        Point_generator_ii g_ii(tet);

        // get 100 random points in tri
        std::copy_n(g_i, 100, std::back_inserter(points_in_tri));

        // get 100 random points in tet
        std::copy_n(g_ii, 100, std::back_inserter(points_in_tet));

        // Check that we have really created 100 points.
        assert( points_in_tri.size() == 100);

        // Check that we have really created 100 points.
        assert( points_in_tet.size() == 100);

        // print the first points
        std::cout << "In triangle: " << points_in_tri[0] << std::endl;
        std::cout << "In tetrahedron: " << points_in_tet[0] << std::endl;

        return 0;
}