4 #include "voro++_2d.hh"
7 const double pi
=3.1415926535897932384626433832795;
8 const double radius
=0.5;
11 // This function returns a random floating point number between 0 and 1
12 double rnd() {return double(rand())/RAND_MAX
;}
15 int i
=0;double x
,y
,arg
;
17 // Initialize the container class to be the unit square, with
18 // non-periodic boundary conditions. Divide it into a 10 by 10 grid, with
19 // an initial memory allocation of 8 particles per grid square.
20 container_2d
con(-1,1,-1,1,10,10,false,false,8);
22 // Add circular wall object
24 for(i
=0,arg
=0;i
<n
;i
++,arg
+=2*pi
/n
) {
25 wc
[i
]=new wall_plane_2d(sin(arg
),-cos(arg
),radius
);
29 // Add 1000 random points to the container
33 if(con
.point_inside(x
,y
)) {
39 // Output the particle positions to a file
40 con
.draw_particles("polygon.par");
42 // Output the Voronoi cells to a file, in the gnuplot format
43 con
.draw_cells_gnuplot("polygon.gnu");
45 // Sum the Voronoi cell areas and compare to the circle area
46 double carea
=n
*radius
*radius
*tan(pi
/n
),varea
=con
.sum_cell_areas();
47 printf("Total polygon area : %g\n"
48 "Total Voronoi cell area : %g\n"
49 "Difference : %g\n",carea
,varea
,varea
-carea
);
51 // Since they were dynamically allocated, delete the wall_plane_2d
53 for(i
=0;i
<n
;i
++) delete wc
[i
];