# Algorithm for merging mesh with cad file

I am writing the pre processing program for a porosity based cfd project we just started. Basically I have a 3 dimensional mesh made of cubes and I need to import a STL file over it, and calculate how much space of each cell is being used by the object. The STL file is a CAD format that uses triangles to represent a surface, but I will assume that it represents a closed surface (a solid).

I made a drawing of the 2D problem: On the STL object is over the mesh. Each cell of the mesh receives a value ranging from 0 to 1 based on how much of the object is over it. Cells 1,2,3,4,5 have a value of 0 while cell 6, have a value of ~.15 and, cell 7 have a value of 1.

So my question is, where do I start? Is there any "surface casting" algorithm? How do I deal with the triangle-cubes conversion?

• The hexahedra in the grid can be converted into triangulated surfaces. The problem then reduces to the computational of the volume of intersection of two three-dimensional polytopes. Efficient algorithms for this calculation can be found in F.P. Preparata and M.I. Shamos. Computational Geometry: An Introduction. Springer-Verlag, New York, 1985 Aug 6, 2014 at 23:50