开发者

Breaking a polygon into "inside" and "outside"

开发者 https://www.devze.com 2023-02-09 23:30 出处:网络
I have a (not necessarily convex) polygon. I\'d like to find a set of rectangles that take up all space in the world bounds ((0,0) to (100,100)) without taking up any space inside the polygon. What\'s

I have a (not necessarily convex) polygon. I'd like to find a set of rectangles that take up all space in the world bounds ((0,0) to (100,100)) without taking up any space inside the polygon. What's the easiest way to find these polygons? Are there algorithms for this sort of thing?

Thanks!

For example, the polygon

 __    __
|  |__|  |
|________|

could be broken in to the following five rectangles:

aaabbbbbbbbbbeee
aaa|  |cc|  |eee
aaa|________|eee
aaaddddddddddeee

or, alternatively, the following six rectangles:

aaaaaaabbccccccc
eee|  |bb|  |ddd
eee|________|ddd
ffffffffffffffff

Is there an ea开发者_如何学运维sy way to break a polygon into the rectangles between the polygon and the world boundaries?


All that I can glean: It's possible but impractical (especially if your polygon has slanted lines). I don't need this answer any more, but I guess that the algorithm would look something like the following:

  • Use triangles to make all edges of the polygon either vertical or horizontal
  • Use four rectangles to cut out as much space as you can on the top/bottom/left/right
    • Now you're left with a polygon that has only vertical/horizontal edges and which extends to every border
  • Greedily place the biggest rectangle you can in the biggest holes in the shape
    • Look for the largest gaps between sides
  • Fill the triangles from step 1 up to a terminal precision
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号