Algorithm required to determine if a rectangle is completely covered by another set of rectangles

前端 未结 7 2259
轻奢々
轻奢々 2021-02-08 13:45

I am searching for an algorithm that will determine if a new rectangle is completely covered by a set of existing rectangles. Another way of putting the question, is does the ne

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 14:02

    You can use the algorithm which is used to calculate the union area of rectangles. As you want to check whether rectangle a is covered by rectangles B={b_1, b_2, ..., }.

    First you calculate the union area of rectangles in B, we get area_1 as the value.

    Then you calculate the union area of rectangles in B+ {a}, we get area_2 as the value.
    So if area_1 == area_2, then you are sure that rectangle a is covered by rectangles B. Otherwise, the answer is false.

    So the main problem is how to calculate union area of rectangles. This problem can be solved by existing excellent algorithm. This algorithm can be brief introduced as first to discretize value of points of rectangles, and then using Segmentation Tree to accelerate calculation of areas of each block.

提交回复
热议问题