Hello,

In my work with DEM (Discrete Element Modeling) I am often approximating a shape, for example a rock, with N spheres. The normal work flow is to load in a STL file that contains the shape that I would like to approximate. I then pack the interior of the stl outline with the N spheres. I try to match the general shape but there really is no rhyme or reason in placing a sphere in a certain location with some radius.

I would like to write/use an algorithm that can find the "best" way to pack a given stl file. I have been looking into the sphere packing problem from mathematics and physics but they do no allow overlapping. 

I have been working on a program in matlab that would do this for me. Its process is as follows.

1) Import a STL file and find its bounding box.

2) Create a bounding grid with dimensions (7,7,7) (for example...)

3) Out of these points, find only the ones that are inside the Polygon

4) Pick a random point from step 3 and minimize a function F solving for the radius of the sphere (more on F in a bit)

5) Repeat steps 3 and step 4, 50 times (for example...)

6) Pick the best minimum value from the step 5s 50 values that minimized F

7) Using the x,y,z values that yielded the minimum value from step 6, reduce the grid such that the grid is now centered around the x,y,z values that minimized F the most. 

8) Repeat steps 3 through 7 until a convergence on x,y,z,r is found.

The function F was a little tricky to formulate and I don't know if it yields exactly what I want, but the general Idea is as follows.

I would like to compare the volumes of the sphere with relationship to the volume of the polygon as follows.

F = (V_s not V_p) - (V_s and V_p) + (V_p not V_s) or

F = Vol of s that is not in the polygon minus the Vol of s that is in the polygon plus the volume of the poly that is not in the spheres

My question is a combination of if anyone has ran into a similar problem and in what ways could I improve my algorithm.

Thank you for any and all suggestions!

Please let me know in what ways I can improve my question.

Similar questions and discussions