# How do I find the portion of a cell/voxel lying within a defined surface?

We have a 3-dimensional grid of voxels (or cells), with individual voxels being of volume $$dx\,dy\,dz$$ where $$dx=dy=dz=1$$.

A cone-like surface is defined by some function, $$z = f(x, y)$$, which in this case is specifically (where $$\epsilon$$, $$w_0$$ and $$r_0$$ are constants):

$$z=\left(\frac{x^2+y^2}{w_0^2r_0^{-2\epsilon}}\right)^{\frac{1}{2\epsilon}}$$

Over the entire grid, how does one compute the fraction of each voxel's volume lying within the volume enclosed by that cone-like surface?

Obviously values should range from $$0\rightarrow1$$ and, in this particular case, voxels positioned at large values of $$x$$ and $$y$$ and small values of $$z$$ have none of their volume within the cone, while those lying at large values of $$z$$, and small values of $$x$$ and $$y$$ are completely enclosed by the cone-like surface.

• It's a task for Marching Cube algorithm. Calculate this field in your voxelized grid: $$\mathcal{f}(x,y,z) = z - \Bigg ( \frac{x^{2}+y^{2}}{w_{0}^{2} r_{0}^{-2 \epsilon}} \Bigg )^{\frac{1}{2 \epsilon}}$$ and finally find the surface that belongs to $\mathcal{f}(x,y,z) = 0$. – Alone Programmer Apr 1 '20 at 18:54
• According to the MC algorithm, the field defines which voxels lie completely in ($f(x,y,z)>0$ for every vertex) and which lie completely out ($f(x,y,z)<0$ for every vertex) of the surface. For the other voxels, a defined grid of $2^8$ 'approximate' surfaces corresponding to different vertex in/out combinations allows for some degree of approximation of fraction of a voxel within the surface. That much I understand, though computing the voxel fractions for each of those possibilities might take a while. I did not however understand your comment to 'find the surface belonging to $f(x,y,z)=0$'? – simonp2207 Apr 3 '20 at 9:22

• Typically my grid will likely contain $\sim10^8-10^9$ voxels, so your AMR-sounding approach may not be too computationally expensive considering it would likely only be computed the once. Thanks for your comment! – simonp2207 Apr 3 '20 at 9:34