Minkowski test code.
[voro++.git] / trunk / src / wall.cc
blob1d126e1e969e62f4e1aa7aa21a85828445ef9329
1 // Voro++, a 3D cell-based Voronoi library
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 /** \file wall.cc
8 * \brief Function implementations for the derived wall classes. */
10 #include "wall.hh"
12 namespace voro {
14 /** Tests to see whether a point is inside the sphere wall object.
15 * \param[in,out] (x,y,z) the vector to test.
16 * \return True if the point is inside, false if the point is outside. */
17 bool wall_sphere::point_inside(double x,double y,double z) {
18 return (x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc)*(z-zc)<rc*rc;
21 /** Cuts a cell by the sphere wall object. The spherical wall is approximated by
22 * a single plane applied at the point on the sphere which is closest to the center
23 * of the cell. This works well for particle arrangements that are packed against
24 * the wall, but loses accuracy for sparse particle distributions.
25 * \param[in,out] c the Voronoi cell to be cut.
26 * \param[in] (x,y,z) the location of the Voronoi cell.
27 * \return True if the cell still exists, false if the cell is deleted. */
28 template<class v_cell>
29 bool wall_sphere::cut_cell_base(v_cell &c,double x,double y,double z) {
30 double xd=x-xc,yd=y-yc,zd=z-zc,dq=xd*xd+yd*yd+zd*zd;
31 if (dq>1e-5) {
32 dq=2*(sqrt(dq)*rc-dq);
33 return c.nplane(xd,yd,zd,dq,w_id);
35 return true;
38 /** Tests to see whether a point is inside the plane wall object.
39 * \param[in] (x,y,z) the vector to test.
40 * \return True if the point is inside, false if the point is outside. */
41 bool wall_plane::point_inside(double x,double y,double z) {
42 return x*xc+y*yc+z*zc<ac;
45 /** Cuts a cell by the plane wall object.
46 * \param[in,out] c the Voronoi cell to be cut.
47 * \param[in] (x,y,z) the location of the Voronoi cell.
48 * \return True if the cell still exists, false if the cell is deleted. */
49 template<class v_cell>
50 bool wall_plane::cut_cell_base(v_cell &c,double x,double y,double z) {
51 double dq=2*(ac-x*xc-y*yc-z*zc);
52 return c.nplane(xc,yc,zc,dq,w_id);
55 /** Tests to see whether a point is inside the cylindrical wall object.
56 * \param[in] (x,y,z) the vector to test.
57 * \return True if the point is inside, false if the point is outside. */
58 bool wall_cylinder::point_inside(double x,double y,double z) {
59 double xd=x-xc,yd=y-yc,zd=z-zc;
60 double pa=(xd*xa+yd*ya+zd*za)*asi;
61 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
62 return xd*xd+yd*yd+zd*zd<rc*rc;
65 /** Cuts a cell by the cylindrical wall object. The cylindrical wall is
66 * approximated by a single plane applied at the point on the cylinder which is
67 * closest to the center of the cell. This works well for particle arrangements
68 * that are packed against the wall, but loses accuracy for sparse particle
69 * distributions.
70 * \param[in,out] c the Voronoi cell to be cut.
71 * \param[in] (x,y,z) the location of the Voronoi cell.
72 * \return True if the cell still exists, false if the cell is deleted. */
73 template<class v_cell>
74 bool wall_cylinder::cut_cell_base(v_cell &c,double x,double y,double z) {
75 double xd=x-xc,yd=y-yc,zd=z-zc,pa=(xd*xa+yd*ya+zd*za)*asi;
76 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
77 pa=xd*xd+yd*yd+zd*zd;
78 if(pa>1e-5) {
79 pa=2*(sqrt(pa)*rc-pa);
80 return c.nplane(xd,yd,zd,pa,w_id);
82 return true;
85 /** Tests to see whether a point is inside the cone wall object.
86 * \param[in] (x,y,z) the vector to test.
87 * \return True if the point is inside, false if the point is outside. */
88 bool wall_cone::point_inside(double x,double y,double z) {
89 double xd=x-xc,yd=y-yc,zd=z-zc,pa=(xd*xa+yd*ya+zd*za)*asi;
90 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
91 pa*=gra;
92 if (pa<0) return false;
93 pa*=pa;
94 return xd*xd+yd*yd+zd*zd<pa;
97 /** Cuts a cell by the cone wall object. The conical wall is
98 * approximated by a single plane applied at the point on the cone which is
99 * closest to the center of the cell. This works well for particle arrangements
100 * that are packed against the wall, but loses accuracy for sparse particle
101 * distributions.
102 * \param[in,out] c the Voronoi cell to be cut.
103 * \param[in] (x,y,z) the location of the Voronoi cell.
104 * \return True if the cell still exists, false if the cell is deleted. */
105 template<class v_cell>
106 bool wall_cone::cut_cell_base(v_cell &c,double x,double y,double z) {
107 double xd=x-xc,yd=y-yc,zd=z-zc,xf,yf,zf,q,pa=(xd*xa+yd*ya+zd*za)*asi;
108 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
109 pa=xd*xd+yd*yd+zd*zd;
110 if(pa>1e-5) {
111 pa=1/sqrt(pa);
112 q=sqrt(asi);
113 xf=-sang*q*xa+cang*pa*xd;
114 yf=-sang*q*ya+cang*pa*yd;
115 zf=-sang*q*za+cang*pa*zd;
116 pa=2*(xf*(xc-x)+yf*(yc-y)+zf*(zc-z));
117 return c.nplane(xf,yf,zf,pa,w_id);
119 return true;
122 // Explicit instantiation
123 template bool wall_sphere::cut_cell_base(voronoicell&,double,double,double);
124 template bool wall_sphere::cut_cell_base(voronoicell_neighbor&,double,double,double);
125 template bool wall_plane::cut_cell_base(voronoicell&,double,double,double);
126 template bool wall_plane::cut_cell_base(voronoicell_neighbor&,double,double,double);
127 template bool wall_cylinder::cut_cell_base(voronoicell&,double,double,double);
128 template bool wall_cylinder::cut_cell_base(voronoicell_neighbor&,double,double,double);
129 template bool wall_cone::cut_cell_base(voronoicell&,double,double,double);
130 template bool wall_cone::cut_cell_base(voronoicell_neighbor&,double,double,double);