Added volume / surface area routines.
[voro++.git] / branches / 2d / examples / boundary / nonconvex_cell.cc
blob5d0c95d3b00e34824b297bb109add0958f7e3f09
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;
9 voronoicell_nonconvex_2d v;
11 // Initialize the Voronoi cell to be a cube of side length 2, centered
12 // on the origin
13 v.init_nonconvex(-1,0.8,-1,0.4,4,5,5,4);
14 v.draw_gnuplot(0,0,"nonconvex_cell.gnu");
15 v.plane(0.3,0);
16 v.plane(0.4,0);
18 // Cut the cell by 100 random planes which are all a distance 1 away
19 // from the origin, to make an approximation to a sphere
20 /*for(int i=0;i<100;i++) {
21 x=2*rnd()-1;
22 y=2*rnd()-1;
23 rsq=x*x+y*y;
24 if(rsq>0.01&&rsq<1) {
25 r=1/sqrt(rsq);x*=r;y*=r;
26 v.plane(x,y,1);
28 }*/
30 // Print out several statistics about the computed cell
31 v.centroid(x,y);
32 printf("Perimeter is %g\n"
33 "Area is %g\n"
34 "Centroid is (%g,%g)\n",v.perimeter(),v.area(),x,y);
36 // Output the Voronoi cell to a file, in the gnuplot format
37 v.draw_gnuplot(0,0,"nonconvex_cell2.gnu");