Minkowski test code.
[voro++.git] / trunk / examples / no_release / split_cell.cc
blobcc83b63b25ba3616793b47f578f42b2c29bce15e
1 // Splitting a Voronoi cell example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 #include "voro++.hh"
8 using namespace voro;
10 // This function returns a random floating point number between 0 and 1
11 double rnd() {return double(rand())/RAND_MAX;}
13 int main() {
14 double x,y,z,rsq,r;
15 voronoicell v,v2;
17 // Initialize the Voronoi cell to be a cube of side length 2, centered
18 // on the origin
19 v.init(-1,1,-1,1,-1,1);
21 // Cut the cell by 250 random planes which are all a distance 1 away
22 // from the origin, to make an approximation to a sphere
23 for(int i=0;i<250;i++) {
24 x=2*rnd()-1;
25 y=2*rnd()-1;
26 z=2*rnd()-1;
27 rsq=x*x+y*y+z*z;
28 if(rsq>0.01&&rsq<1) {
29 r=1/sqrt(rsq);x*=r;y*=r;z*=r;
30 v.plane(x,y,z,1);
34 // Make copy of the Voronoi cell
35 v2=v;
37 // Cut one copy in one direction, and the other copy in the other direction
38 v.plane(1,0,0,0);
39 v2.plane(-1,0,0,0);
41 // Output the Voronoi cell to a file, in the gnuplot format
42 v.draw_gnuplot(-0.05,0,0,"split_cell1.gnu");
43 v2.draw_gnuplot(0.05,0,0,"split_cell2.gnu");