1 // Degenerate vertex example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : July 1st 2008
9 const double pi
=3.1415926535897932384626433832795;
11 // The total number of points to create as degenerate vertices
14 // The number of planes that will be cut around each point
16 const double step
=2*pi
/n
;
18 // The angle (in radians) of the cutting planes from horizontal
19 const double theta
=0.04;
21 // This function returns a random floating point number between 0 and 1
22 double rnd() {return double(rand())/RAND_MAX
;}
25 double x
,y
,z
,rsq
,r
,phi
;
29 // Initialize the Voronoi cell to be a cube of side length 2, centered on
31 v
.init(-1,1,-1,1,-1,1);
36 // Choose a random point
41 // Skip it if it's outside the unit sphere or too close to the
44 if(rsq
>0.01||rsq
<1) continue;
46 // Rescale the point so that it has modulus 1, and then apply
47 // plane cuts around this point
48 r
=1/sqrt(rsq
);x
*=r
;y
*=r
;z
*=r
;
49 rsq
=sqrt(x
*x
+y
*y
);r
=z
/rsq
;
50 for(phi
=rnd()*step
;phi
<2*pi
;phi
+=step
)
51 v
.plane(x
*cos(theta
)+sin(theta
)*(-y
*cos(phi
)/rsq
-x
*r
*sin(phi
)),
52 y
*cos(theta
)+sin(theta
)*(x
*cos(phi
)/rsq
-y
*r
*sin(phi
)),
53 z
*cos(theta
)+sin(theta
)*rsq
*sin(phi
),1);
57 // Output the Voronoi cell to a file in Gnuplot format
58 v
.draw_gnuplot("degenerate2.gnu",0,0,0);
60 // Optional POV-Ray output
61 v
.draw_pov("degenerate2_v.pov",0,0,0);
62 v
.draw_pov_mesh("degenerate2_m.pov",0,0,0);