// Cell cutting region example code // // Author : Chris H. Rycroft (LBL / UC Berkeley) // Email : chr@alum.mit.edu // Date : August 30th 2011 #include "voro++.hh" using namespace voro; const double pi=3.1415926535897932384626433832795; // This constant sets the tolerance in the bisection search algorithm const double tolwidth=1e-7; // This constant determines the density of points to test const double theta_step=pi/200; int main() { double x,y,z,r,rmin,rmax; double theta,phi,phi_step; voronoicell v; FILE *fp=safe_fopen("cell_cut_region.gnu","w"); // Initialize the Voronoi cell to be an octahedron and make a single // plane cut to add some variation v.init_octahedron(1); v.plane(0.4,0.3,1,0.1); // Output the cell in gnuplot format v.draw_gnuplot(0,0,0,"cell.gnu"); // Now test over direction vectors from the center of the sphere. For // each vector, carry out a search to find the maximum distance along // that vector that a plane will intersect with cell, and save it to // the output file. for(theta=theta_step*0.5;thetatolwidth) { r=(rmax+rmin)*0.5; if (v.plane_intersects(x,y,z,r)) rmin=r; else rmax=r; } // Output this point to file r=(rmax+rmin)*0.5; x*=r;y*=r;z*=r; fprintf(fp,"%g %g %g\n",x,y,z); } } fclose(fp); }