Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / dynamic / examples / basic / single_cell.cc
blobf4c91be796ccf6591f6e2a4a8c095dcd335adf8d
1 // Single Voronoi cell example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : July 1st 2008
7 #include "voro++.cc"
9 // This function returns a random floating point number between 0 and 1
10 double rnd() {return double(rand())/RAND_MAX;}
12 int main() {
13 double x,y,z,rsq,r;
14 voronoicell v;
16 // Initialize the Voronoi cell to be a cube of side length 2, centered
17 // on the origin
18 v.init(-1,1,-1,1,-1,1);
20 // Cut the cell by 250 random planes which are all a distance 1 away
21 // from the origin, to make an approximation to a sphere
22 for(int i=0;i<250;i++) {
23 x=2*rnd()-1;
24 y=2*rnd()-1;
25 z=2*rnd()-1;
26 rsq=x*x+y*y+z*z;
27 if(rsq>0.01&&rsq<1) {
28 r=1/sqrt(rsq);x*=r;y*=r;z*=r;
29 v.plane(x,y,z,1);
33 // Output the Voronoi cell to a file, in the gnuplot format
34 v.draw_gnuplot("single_cell.gnu",0,0,0);