Strip extra spaces from code.
[voro++.git] / branches / dynamic / examples / extra / superellipsoid.cc
blob101908d8c5f89fe2f32862c9fd97cb56bb424ba8
1 // Superellipsoid 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 5000 random planes that are scaled to create a
21 // superellipsoid
22 for(int i=0;i<5000;i++) {
23 x=2*rnd()-1;
24 y=2*rnd()-1;
25 z=2*rnd()-1;
26 rsq=x*x*x*x+y*y*y*y+z*z*z*z;
27 if(rsq>0.01&&rsq<1) {
28 r=1/sqrt(sqrt(rsq));
29 x*=r;y*=r;z*=r;
30 v.plane(x*x*x,y*y*y,z*z*z,x*x*x*x+y*y*y*y+z*z*z*z);
34 // Output the Voronoi cell to a file, in the gnuplot format
35 v.draw_gnuplot("superellipsoid.gnu",0,0,0);
37 // Output the Voronoi cell to a file in POV-Ray formats
38 v.draw_pov("superellipsoid_v.pov",0,0,0);
39 v.draw_pov_mesh("superellipsoid_m.pov",0,0,0);