Strip extra spaces from code.
[voro++.git] / branches / 2d / examples / basic / random_points_2d.cc
blob90eab1f144ab7c628c8bb65f9aff2b8aa2298982
1 #include "voro++_2d.hh"
2 using namespace voro;
4 // This function returns a random floating point number between 0 and 1
5 double rnd() {return double(rand())/RAND_MAX;}
7 int main() {
8 int i;double x,y;
10 // Initialize the container class to be the unit square, with
11 // non-periodic boundary conditions. Divide it into a 10 by 10 grid,
12 // with an initial memory allocation of 16 particles per grid square.
13 container_2d con(0,1,0,1,10,10,false,false,16);
15 // Add 1000 random points to the container
16 for(i=0;i<1000;i++) {
17 x=rnd();
18 y=rnd();
19 con.put(i,x,y);
22 // Output the particle positions to a file
23 con.draw_particles("random_points_2d.par");
25 // Output the Voronoi cells to a file, in the gnuplot format
26 con.draw_cells_gnuplot("random_points_2d.gnu");
28 // Sum the Voronoi cell areas and compare to the container area
29 double carea=1,varea=con.sum_cell_areas();
30 printf("Total container area : %g\n"
31 "Total Voronoi cell area : %g\n"
32 "Difference : %g\n",carea,varea,varea-carea);