Calculate the fraction of volume of a rectilinear grid cell within some radius of the origin

262 Views Asked by At

I have a sphere (radius $R$) on a rectilinear grid. Some cells intersect the edge of that sphere, call them 'edge cells'. Designate a given cell by indices $[i,j,k]$ which refer to the lowest-index vertex of that cell (i.e. the inner-most cell, in the $[+x,+y,+z]$ octant would be designated as $[0,0,0]$). For any given 'edge cell', how can I calculate what fraction of its volume is within the sphere of radius $R$?

In this figure, the purple surface is the surface of the sphere passing through some arbitrary cell, with origin $[x_0, y_0, z_0]$. I want to know what fraction of the cell's volume is within this surface.

I think 'edge cells' can be calculated by finding the cells whose vertex $[i,j,k]$ is at a radius $<R$, but whose vertex $[i+1,j+1,k+1]$ has radius $>R$.

I think there should be an analytic formula to calculate the volume fraction, but I can't figure out how to setup the integral. Any help would be greatly appreciated!

enter image description here