What is an elegant algorithm for placing rectangles of different sizes in a circle?

I have a bunch of variable-sized rectangles that I need to combine around a circle, presumably with the largest in the center.

NB. The circle does not have a fixed size - this is just the general form that I need.

This is more like the way I present lazy human packages (when the piece is in place, it remains.)

They are already ordered by the maximum of their width and height, the largest in magnitude.

Ideally - and I think this can be guaranteed by order - there would be no gaps at all.

The algorithm I'm struggling with:

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

, , , ( ) .

, , , (?) , .

+5
2

" " - ? , .

" , , "? , , . .

<Loop> / . , , .

, ( ). , .

, , , , . </Loop>

, ? ? ?

, , -:

class Point(object):
    x, y: Integer
class Rectangle(object):
"""Assuming that the orientation doesn't matter, length>=width"""
    length, width: Integer
class Edge(object):
    from, to: Point
    length: Integer
class Pile_Of_Rectangles(object):
    edges: list of Edges #clockwise
    def add_rectangle(r):
        search longest edge "e1"
        search the longer of the two adjacent edges "e2"
        attach r with its longer side to "e1" at the end, where it adjoins to "e2":
            adjust "e1" so that e1.length = e1.length - r.length
            insert the new edges with length r.width, r.length and r.width into self.edges
            connect the last edge with "e2"

, . , , ( ).

+2

1. ? 2. ? , , , , ?

, . , , .

0

All Articles