1 #include "voro++_2d.hh"
4 const double pi
=3.1415926535897932384626433832795;
5 const double radius
=0.95;
7 // This function returns a random floating point number between 0 and 1
8 double rnd() {return double(rand())/RAND_MAX
;}
13 // Initialize the container class to be the unit square, with
14 // non-periodic boundary conditions. Divide it into a 6 by 6 grid, with
15 // an initial memory allocation of 16 particles per grid square.
16 container_2d
con(-1,1,-1,1,10,10,false,false,16);
18 // Add circular wall object
19 wall_circle_2d
wc(0,0,radius
);
22 // Add 1000 random points to the container
26 if(con
.point_inside(x
,y
)) con
.put(i
,x
,y
);
29 // Output the particle positions to a file
30 con
.draw_particles("circle.par");
32 // Output the Voronoi cells to a file, in the gnuplot format
33 con
.draw_cells_gnuplot("circle.gnu");
35 con
.print_custom("%i %q %a %n","circle.vol");
37 // Sum the Voronoi cell areas and compare to the circle area
38 double carea
=pi
*radius
*radius
,varea
=con
.sum_cell_areas();
39 printf("Total circle area : %g\n"
40 "Total Voronoi cell area : %g\n"
41 "Difference : %g\n",carea
,varea
,varea
-carea
);