I am looking some code to packing 3D spheres with the same radius - r in a rectangle box - xmin, ymin, zmin and xmax, ymax, zmax. In other word, a function with input: r, xmin, ymin, zmin and xmax, ymax, zmax and output: x(i), y(i), z(i), N, which are coordinates of the sphere center and the number of spheres in the box. The packing should be close the highest density with no overlap of spheres. The maximum packing density is 74.05% or the minimum void ratio = 25.95% among various packing.
Packing spheres | plus.maths.org[
^][
^]
[x,y,z,N]=function spherePackingMinimumVoid (r, xmin, ymin, zmin and xmax, ymax, zmax)
C++, or Fortran or Matlab code.
Thank you
What I have tried:
I tried the least dense packing, which is putting spheres in cube grids. The void ratio is 47.64%, which is not a good packing.