小编Lon*_*ars的帖子

将不同大小的矩形拟合成圆形的优雅算法是什么?

我有一堆可变大小的矩形,我需要将它们大致组合成一个圆圈,大概是中心的最大的矩形.

NB.圆圈的大小不是固定的 - 这只是我追求的整体形状.

这更像是我想象一个懒惰的人类包(一旦一件就到位,它就会停留.)

它们已按其宽度和高度的最大值排序,最大值.

理想情况下 - 我认为这可以通过订购得到保证 - 根本没有差距.

我正在努力的算法是:

for each rectangle:
    if first:
        place rectangle at origin
        add all edges to edge list
    else:
        for each edge in edge list:
            if edge is long enough to accomodate rectangle (length <= width or height depending on orientation):
                if rectangle placed on this edge does not collide with any other edges:
                    calculate edge score (distance of mid-point from origin)
        use edge with lowest edge score
        place rectangle on …
Run Code Online (Sandbox Code Playgroud)

python algorithm packing

5
推荐指数
1
解决办法
1544
查看次数

标签 统计

algorithm ×1

packing ×1

python ×1