1 // Irregular packing example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
10 // Set the number of particles that are going to be randomly introduced
11 const int particles
=20;
13 // This function returns a random double between 0 and 1
14 double rnd() {return double(rand())/RAND_MAX
;}
16 // Create a wall class that will initialize the Voronoi cell to fill the
18 class wall_l_shape
: public wall
{
22 v
.draw_gnuplot(0,0,0,"l_shape_init.gnu");
24 bool point_inside(double x
,double y
,double z
) {return true;}
25 bool cut_cell(voronoicell
&c
,double x
,double y
,double z
) {
27 // Set the cell to be equal to the L-shape
29 c
.translate(-x
,-y
,-z
);
31 // Set the tolerance to 100, to make the code search
32 // for cases where non-convex cells are cut in multiple
37 bool cut_cell(voronoicell_neighbor
&c
,double x
,double y
,double z
) {
39 // Set the cell to be equal to the L-shape
41 c
.translate(-x
,-y
,-z
);
43 // Set the tolerance to 100, to make the code search
44 // for cases where non-convex cells are cut in multiple
58 container
con(-1,1,-1,1,-1,1,5,5,5,false,false,false,8);
60 // Create the L-shape wall class and add it to the container
64 // Add particles, making sure not to place any outside of the L-shape
68 if(x
<0&&y
>0) continue;
74 // Check the Voronoi cell volume; it should be 6
75 printf("Voronoi cell volume: %.8g\n",con
.sum_cell_volumes());
77 // Save the particles and Voronoi cells in gnuplot format
78 con
.draw_particles("l_shape_p.gnu");
79 con
.draw_cells_gnuplot("l_shape_v.gnu");