1 // Odd/even face coloring code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
13 // This function returns a random floating point number between 0 and 1
14 double rnd() {return double(rand())/RAND_MAX
;}
21 // Initialize the Voronoi cell to be a cube of side length 2, centered
23 v
.init(-1,1,-1,1,-1,1);
25 // Cut the cell by 250 random planes which are all a distance 1 away
26 // from the origin, to make an approximation to a sphere
33 r
=1/sqrt(rsq
);x
*=r
;y
*=r
;z
*=r
;
38 // Calculate the orders of the faces and the normal vectors
41 v
.face_orders(f_vert
);
44 // Output POV-Ray planes with textures based on whether a face is
45 // composed of an odd or even number of edges
46 const char* parity
[2]={"even","odd"};
47 FILE *fp
=safe_fopen("odd_even_pl.pov","w");
48 for(i
=0;i
<f_vert
.size();i
++)
49 fprintf(fp
,"plane{<%g,%g,%g>,0.5 texture{t_%s}}\n"
50 ,nor
[3*i
],nor
[3*i
+1],nor
[3*i
+2]
51 ,parity
[f_vert
[i
]&1]);
54 // Save the Voronoi cell as a spheres and cylinders
55 v
.draw_pov(0,0,0,"odd_even_v.pov");