Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / 2d_boundary / examples / test_cell.cc
blob66023e4bf3d7da46ce0394ab02e26acc2d091f8d
1 #include "voro++_2d.hh"
3 // This function returns a random floating point number between 0 and 1
4 double rnd() {return double(rand())/RAND_MAX;}
6 int main() {
7 double x,y,rsq,r;
8 voronoicell_2d v;
10 // Initialize the Voronoi cell to be a cube of side length 2, centered
11 // on the origin
12 v.init(-1,1,-1,1);
14 // Cut the cell by 100 random planes which are all a distance 1 away
15 // from the origin, to make an approximation to a sphere
16 for(int i=0;i<100;i++) {
17 x=2*rnd()-1;
18 y=2*rnd()-1;
19 rsq=x*x+y*y;
20 if(rsq>0.01&&rsq<1) {
21 r=1/sqrt(rsq);x*=r;y*=r;
22 v.plane(x,y,1);
26 // Print out several statistics about the computed cell
27 v.centroid(x,y);
28 printf("Perimeter is %g\n"
29 "Area is %g\n"
30 "Centroid is (%g,%g)\n",v.perimeter(),v.area(),x,y);
32 // Output the Voronoi cell to a file, in the gnuplot format
33 v.draw_gnuplot(0,0,"single_cell.gnu");