J
J
John2019-03-12 19:41:29
Mathematics
John, 2019-03-12 19:41:29

How to pack balls in the form of a sphere?

For example we have 10 balls. What algorithm can be used to pack balls in the form of a sphere?
There are some articles, but it describes how to fill the sphere with balls, but I do not need to fill, but arrange the balls in the form of a sphere.
https://en.wikipedia.org/wiki/Dense_packing_equal...
https://en.wikipedia.org/wiki/Sphere_packing_in_a_...
If you follow the algorithm from the first article, you get this construction. Here a cube is created from balls, and only suitable balls are taken, as a result we get a sphere, but the number of balls comes from the radius of the sphere (var count) and the task is that there are already some number of balls, and they need to be decomposed in the form of a sphere.

var count = 10;

for (int k = -count; k < count; k++)
{
  for (int i = -count; i < count; i++)
  {
    for (int j = -count; j < count; j++)
    {
      var x = 2 * i + (j + k) % 2;
      var y = Mathf.Sqrt(3) * (j + 1 / 3 * (k % 2));
      var z = Mathf.Sqrt(8 / 3) * k;

      if (x * x + y * y + z * z <= count * count)
      {
         // vector = Vector3(x, y, z);
      }
    }
  }
}

Visualization
5c87e1595b648135857622.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question