Rectangle packing around a center point

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:

10

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:

  • 0 : top left
  • 1 : top right
  • 2 : bottom right
  • 3 : bottom left

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật