minimizing overlap in random rectangles

前端 未结 5 1760
时光取名叫无心
时光取名叫无心 2021-02-09 03:14

I have a number of possibly overlapping rectangles, of random size and position within a fixed plane. Since these rectangles are random, some may not overlap:

|-----
         


        
5条回答
  •  梦谈多话
    2021-02-09 03:39

    If you don't already have a set of rectangles, you could approach it from the other way - start with a large rectangle and subdivide it until you have a set that you can work with - that will ensure that you have no overlaps.

    Start with a whole rectangle

    --------
    |      |
    |      |
    |      |
    |      |
    |      |
    --------
    

    Split at a random point and store the two rectangles.

    --------
    |      |
    |------|
    |      |
    |      |
    |      |
    --------
    

    Split a random rectangle at a random point

    --------
    |      |
    |------|
    | |    |
    | |    |
    | |    |
    --------
    

    repeat . . .

    --------
    |      |
    |------|
    | |    |
    | |----|
    | |    |
    --------
    

    Stop when you have the required number of rectangles.

    You could make this produce the kind of 'randomness' that you want by choosing more carefully the rectangle that you are going to split each time etcc

提交回复
热议问题