How can I build up the densely packing spheres, starting from a single one, in C++? [closed]

StackOverflow https://stackoverflow.com/questions/14013530

  •  12-12-2021
  •  | 
  •  

سؤال

Let's assume that I start out with a single sphere of a defined radius R, and an array of three elements, containing the cartesian coordinates:

double vecpos[3];
vecpos[0]= 0.0;
vecpos[1]= 0.0;
vecpos[2]= 0.0;
double radius= 5;

Now, I would like to add additional spheres. These additional spheres should be ideally packed, as dense as possible.

I am looking for an algorithm that, starting from this single sphere, will add more ones in a most densly packed way. The spheres may, of course, not overlap (i.e., the behave like solid marbles).

My attempts thus far were centered on adding more spheres (e.g. to the left and right of the original one, so at position:

(10,0,0) 
(-10,0,0)

then adding new ones on the top and bottom (at calculated positions:

(5, sqrt(3)/2 * 10, 0)
(-5, sqrt(10)/2 * 10, 0)
(5, sqrt(3)/2 * -10, 0)
(-5, sqrt(3)/2 * -10, 0)

(creating a hexagon of the centers). Up to this point, I realize that I can keep building up new spheres with a simple algorithm which just creates equi-distant triangles which use the centres of two spheres to create a third sphere (this is how I calculated the positions of the four new spheres above).

However, moving into the third dimension (i.e.: Adding new spheres on top or below the others) is where I got stuck, since I don't see a way to intelligently write a code to do it.

Any suggestions which solve my problem or are simpler than my solution are highly welcome.

Thank you.

هل كانت مفيدة؟

المحلول

The basis for this is the concept of a regular simplex. If all the sphere are the same radius, it is merely a matter of generating more and more regular simplexes. In 2D, the regular simplex is an equilateral triangle. In 3D, the regular simplex is an equilateral tetrahedron (as shown on the wiki page). Notice that once you have a triangle, you can create the tetrahedron by creating another point (at a calculated distance) on either sides of the plane of the triangle. So, you can create two tetrahedrons out of that triangle. At this point, every triangular face of that volume is also an equilateral triangle, and by creating a new point to the outside of each triangular face, you create a new tetrahedron for each of these. And you can repeat that process with every new face that is created (three new faces are created for each tetrahedron that you create). And you can use this algorithm to generate either a tightly packed set of spheres (with centers at the points of the tetrahedrons, and radius of half the length of the sides of the tetrahedrons), or to create a tetrahedral "grid" (a sort of volumetric version of triangular grids or meshes that are common in various applications).

نصائح أخرى

Once you have three of those spheres in a triangle, you can stack one atop them. The x and y coordinates of the new sphere will be the average of the three below, and the added height will be 2 sqrt(6)R/3. So if the lower three are

A = (0, 0, 0)
B = (2R, 0, 0)
C = (R, sqrt(3)R, 0)

Then the new one will be

D = (R, sqrt(3)R/3, 2 sqrt(6)R/3)

Once you have that one sphere in the second layer, you can add more spheres in that layer, by the method you describe above.

Note that you have a choice about which triangle to choose...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top