Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / 2d / examples / basic / single_cell_2d.cc
blob71e68093800b9236d04d5f5984db78649185824e
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 double x,y,rsq,r;
9 voronoicell_2d v;
11 // Initialize the Voronoi cell to be a cube of side length 2, centered
12 // on the origin
13 v.init(-1,1,-1,1);
15 // Cut the cell by 100 random planes which are all a distance 1 away
16 // from the origin, to make an approximation to a sphere
17 for(int i=0;i<100;i++) {
18 x=2*rnd()-1;
19 y=2*rnd()-1;
20 rsq=x*x+y*y;
21 if(rsq>0.01&&rsq<1) {
22 r=1/sqrt(rsq);x*=r;y*=r;
23 v.plane(x,y,1);
27 // Print out several statistics about the computed cell
28 v.centroid(x,y);
29 printf("Perimeter is %g\n"
30 "Area is %g\n"
31 "Centroid is (%g,%g)\n",v.perimeter(),v.area(),x,y);
33 // Output the Voronoi cell to a file, in the gnuplot format
34 v.draw_gnuplot(0,0,"single_cell_2d.gnu");