minimizing overlap in random rectangles

前端 未结 5 1766
时光取名叫无心
时光取名叫无心 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:18

    If you don't have any constraint on the number of rectangles that your algorithm should produce, you can definitely be rash in your treatment!

    1. Easiest solution ever

    Create a set of all the squares (of area 1) that are covered by the rectangles of the input set. A square being a rectangle... there you are!

    2. Minimalist solution ?

    Okay, that was rash, however I don't think you should worry about the input set. You problem is in fact different:

    Pick up a contiguous area with a complex shape and try and cover it exactly with rectangles, minimizing their number and so that they do not overlap.

    Of course, your area may not be contiguous, but it just means you have several contiguous areas you can work on independently.

    Now, I freely admit I do not know the best solution for this problem, there are various approaches I can envision and I don't know their performances or result. KD-Tree should yield a solution, don't know if it's the minimalist one though!

提交回复
热议问题