There is list of rectangles with different (known) widths and heights. The rectangles ( or boxes ) cannot be rotated.The algorithm should be able to handle hundreds of boxes of arbitrary dimensions.
How to pack those rectangles around center point so that the result look something like this. An even distribution around the central point and minimal gaps between boxes.
The usual bin packing algorithms require modification to handle this situation where there is no obvious fixed dimension container or containers to pack the boxes into.
Input box dimensions
( 4 4),( 5 2),( 7 5),( 2 7),( 4 5),( 2 6),( 6 6),( 8 4),( 4 5),( 4 9),
( 4 5),( 7 8),( 8 3),( 9 6),( 9 2),( 9 9),( 4 8),( 5 3),( 2 8),( 2 7),
( 4 2),( 6 3),( 7 8),( 4 6),( 4 2),( 9 4),( 3 4),( 5 7),( 9 6),( 3 9),
( 7 4),( 4 8),( 6 8),( 8 9),( 7 5),( 7 8),( 8 5),( 8 6),( 4 5),( 8 4),
( 9 6),( 5 7),( 8 8),( 3 4),( 9 3),( 7 6),( 6 6),( 2 6),( 8 3),( 8 3)
Output should look something like this:
This uses standard bin packing techniques. Here there is no container or containers of regular dimensions into which the boxes are packed. Instead boxes are to be arranged as tightly and neatly as possible around a central point.
One way I like to think of this is that it simulates crystal growth from a saturated solution. The boxes are molecules floating around in the solution. Occasionally a box finds the perfect spot on the growing crystal where it fits perfectly. Out of random Brownian motion, large scale order emerges, building a beautiful crystal.
The 2D space around the central point is divided into 4 quadrants
Quadrant indices:
So that the same code can be used to pack all quadrants, each quadrant is rotated into the orientation of the bottom right quadrant, packed, and then rotated back, with all its packed boxes, into its final position. The bottom right quadrant was chosen because the distance of a point from the central packing point is simply calculated by summing the x and y co-ordinates.
The quadrant concept gives us 4 containers to pack. Each container is a right angled triangle, with the hypotenuse open so we can keep filling the containers up for as long as we need. The boxes to be packed are sorted into order of decreasing area and assigned to the quadrants in round robin fashion ( box 0 to quadrant 0, box 1 to quadrant 1, ... box 3 to quadrant 0, box 5 to quadrant 1, ... ). The round robin assignment ensures that each quadrant gets boxes of approximately the same total area.
Blocks of unused space are used to keep track of where the next box might best be fitted. There are several algorithms that can be used for identifying the best space for a particular block, the choice made according the details of what exactly the user is optimizing for ( minimal gaps between blocks, or minimal average distance from central point, or performance, or ... ).
When a suitable space is found it will in general be larger than the box being packed, so the space is split into 2 new, smaller blocks of unused space. Because the boxes are packed in order of decreasing size, later boxes can usually be fitted into the small gaps left between the earlier, larger packed boxes.
Here are some results from this algorithm, using alternative algorithms for selecting the best space for each block
A C++ implementation of this algorithm and a VSCODE project to build it is available at https://github.com/JamesBremner/so79276745