我有一堆大小不同的矩形需要大致地拼成一个圆形,最大的矩形应该位于中心位置。注意:圆形的大小不是固定的,那只是我想要的整体形状。
这更像是懒人的打包方式(一旦放置好了,就留在原地)。
它们已经按宽度和高度的最大值排序,最大的排在前面。理想情况下,通过排序可以保证没有任何间隙。
我正在苦恼的算法是:
这更像是懒人的打包方式(一旦放置好了,就留在原地)。
它们已经按宽度和高度的最大值排序,最大的排在前面。理想情况下,通过排序可以保证没有任何间隙。
我正在苦恼的算法是:
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 edge
for each of this rectangles edges:
if edge overlaps one already in the edge list:
merge or remove edge
else:
add to edge list
remove used edge from edge list
add unused sections of this edge into edge list
这对于前几个矩形运作良好,但是边缘合并非常棘手,我目前选择使用哪个边缘部分的方法(一端或另一端)往往会留下很多间隙。
虽然我认为最终我会让这种方法相当令人满意,但感觉有一种更优雅的(图?)算法我还没有掌握。