Reset platonic code.
[voro++.git] / branches / dynamic / src / wall.cc
blobe2618d4761f79e53ada717017ccff62ae9687c2a
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 : July 1st 2008
7 /** \file wall.cc
8 * \brief Function implementations for the derived wall classes. */
10 #include "wall.hh"
12 /** Tests to see whether a point is inside the sphere wall object.
13 * \param[in] (x,y,z) the vector to test.
14 * \return true if the point is inside, false if the point is outside. */
15 bool wall_sphere::point_inside(fpoint x,fpoint y,fpoint z) {
16 return (x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc)*(z-zc)<rc*rc;
19 /** Cuts a cell by the sphere wall object. The spherical wall is approximated by
20 * a single plane applied at the point on the sphere which is closest to the center
21 * of the cell. This works well for particle arrangements that are packed against
22 * the wall, but loses accuracy for sparse particle distributions.
23 * \param[in] &c the Voronoi cell to be cut.
24 * \param[in] (x,y,z) the location of the Voronoi cell.
25 * \return true if the cell still exists, false if the cell is deleted. */
26 template<class n_option>
27 inline bool wall_sphere::cut_cell_base(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z) {
28 fpoint xd=x-xc,yd=y-yc,zd=z-zc,dq;
29 dq=xd*xd+yd*yd+zd*zd;
30 if (dq>tolerance) {
31 dq=2*(sqrt(dq)*rc-dq);
32 return c.nplane(xd,yd,zd,dq,w_id);
34 return true;
37 /** Finds the vector of minimum distance from a given position vector to the
38 * sphere wall object.
39 * \param[in] (x,y,z) the vector to test.
40 * \param[in] (&dx,&dy,&dz) the vector of minimum distance to the wall. */
41 void wall_sphere::min_distance(fpoint x,fpoint y,fpoint z,fpoint &dx,fpoint &dy,fpoint &dz) {
42 fpoint rad=sqrt(x*x+y*y+z*z);
43 if(rad>tolerance) {
44 rad=rc/rad-1;
45 dx=x*rad;dy=y*rad;dz=z*rad;
46 } else {
47 dx=rc;dy=dz=0;
51 /** Tests to see whether a point is inside the plane wall object.
52 * \param[in] (x,y,z) the vector to test.
53 * \return true if the point is inside, false if the point is outside. */
54 bool wall_plane::point_inside(fpoint x,fpoint y,fpoint z) {
55 return x*xc+y*yc+z*zc<ac;
58 /** Cuts a cell by the plane wall object.
59 * \param[in] &c the Voronoi cell to be cut.
60 * \param[in] (x,y,z) the location of the Voronoi cell.
61 * \return true if the cell still exists, false if the cell is deleted. */
62 template<class n_option>
63 inline bool wall_plane::cut_cell_base(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z) {
64 fpoint dq=2*(ac-x*xc-y*yc-z*zc);
65 return c.nplane(xc,yc,zc,dq,w_id);
68 /** Finds the vector of minimum distance from a given position vector to the
69 * plane wall object.
70 * \param[in] (x,y,z) the vector to test.
71 * \param[in] (&dx,&dy,&dz) the vector of minimum distance to the wall. */
72 void wall_plane::min_distance(fpoint x,fpoint y,fpoint z,fpoint &dx,fpoint &dy,fpoint &dz) {
73 const fpoint mag=1/(xc*xc+yc*yc+zc*zc);
74 fpoint dq=(ac-x*xc-y*yc-z*zc)*mag;
75 dx=xc*dq;
76 dy=yc*dq;
77 dz=zc*dq;
80 /** Tests to see whether a point is inside the cylindrical wall object.
81 * \param[in] (x,y,z) the vector to test.
82 * \return true if the point is inside, false if the point is outside. */
83 bool wall_cylinder::point_inside(fpoint x,fpoint y,fpoint z) {
84 fpoint xd=x-xc,yd=y-yc,zd=z-zc;
85 fpoint pa=(xd*xa+yd*ya+zd*za)*asi;
86 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
87 return xd*xd+yd*yd+zd*zd<rc*rc;
90 /** Cuts a cell by the cylindrical wall object. The cylindrical wall is
91 * approximated by a single plane applied at the point on the cylinder which is
92 * closest to the center of the cell. This works well for particle arrangements
93 * that are packed against the wall, but loses accuracy for sparse particle
94 * distributions.
95 * \param[in] &c the Voronoi cell to be cut.
96 * \param[in] (x,y,z) the location of the Voronoi cell.
97 * \return true if the cell still exists, false if the cell is deleted. */
98 template<class n_option>
99 inline bool wall_cylinder::cut_cell_base(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z) {
100 fpoint xd=x-xc,yd=y-yc,zd=z-zc;
101 fpoint pa=(xd*xa+yd*ya+zd*za)*asi;
102 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
103 pa=xd*xd+yd*yd+zd*zd;
104 if(pa>1e-5) {
105 pa=2*(sqrt(pa)*rc-pa);
106 return c.nplane(xd,yd,zd,pa,w_id);
108 return true;
111 void wall_cylinder::min_distance(fpoint x,fpoint y,fpoint z,fpoint &dx,fpoint &dy,fpoint &dz) {
112 fpoint xd=x-xc,yd=y-yc,zd=z-zc;
113 fpoint pa=(xd*xa+yd*ya+zd*za)*asi;
114 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
115 pa=xd*xd+yd*yd+zd*zd;
116 if(pa>1e-5) {
117 pa=(sqrt(pa)*rc-pa);
118 dx=xd*pa*pa;
119 dy=yd*pa*pa;
120 dz=zd*pa*pa;
121 } else {
122 dx=dy=dz=0;
126 /** Tests to see whether a point is inside the cone wall object.
127 * \param[in] (x,y,z) the vector to test.
128 * \return true if the point is inside, false if the point is outside. */
129 bool wall_cone::point_inside(fpoint x,fpoint y,fpoint z) {
130 cout << x << y << z << endl;
131 fpoint xd=x-xc,yd=y-yc,zd=z-zc;
132 fpoint pa=(xd*xa+yd*ya+zd*za)*asi;
133 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
134 pa*=gra;
135 if (pa<0) return false;
136 pa*=pa;
137 return xd*xd+yd*yd+zd*zd<pa;
140 /** Cuts a cell by the cone wall object. The conical wall is
141 * approximated by a single plane applied at the point on the cone which is
142 * closest to the center of the cell. This works well for particle arrangements
143 * that are packed against the wall, but loses accuracy for sparse particle
144 * distributions.
145 * \param[in] &c the Voronoi cell to be cut.
146 * \param[in] (x,y,z) the location of the Voronoi cell.
147 * \return true if the cell still exists, false if the cell is deleted. */
148 template<class n_option>
149 inline bool wall_cone::cut_cell_base(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z) {
150 fpoint xd=x-xc,yd=y-yc,zd=z-zc;
151 fpoint xf,yf,zf,imoda;
152 fpoint pa=(xd*xa+yd*ya+zd*za)*asi;
153 xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
154 pa=xd*xd+yd*yd+zd*zd;
155 if(pa>1e-5) {
156 pa=1/sqrt(pa);
157 imoda=sqrt(asi);
158 xf=-sang*imoda*xa+cang*pa*xd;
159 yf=-sang*imoda*ya+cang*pa*yd;
160 zf=-sang*imoda*za+cang*pa*zd;
161 pa=2*(xf*(xc-x)+yf*(yc-y)+zf*(zc-z));
162 return c.nplane(xf,yf,zf,pa,w_id);
164 return true;
167 void wall_cone::min_distance(fpoint x,fpoint y,fpoint z,fpoint &dx,fpoint &dy,fpoint &dz) {