Reputation: 83254
I have a big polygon (Pa
). Inside the polygon there are a lot of small "holes", as shown:
Here are a few condition for the holes:
How to obtain the remaining polygon ( or the polygon list) in an efficient manner? The easiest way ( brute force way) is to take the Pa
, and gradually computing the remaining polygon by subtracting out the holes. Although this idea is feasible, but I suspect that there is a more efficient algorithm.
Edit: I'm not asking about how to perform polygon clipping ( or subtraction) algorithm! In fact that's something I would do by brute force. I'm asking in addition to the polygon clipping method ( take the main polygon and then gradually clip the holes out), is there other more efficient way?
Upvotes: 6
Views: 3878
Reputation: 70314
This is very hard to do in a general manner. You can find source code for a solution here:
Upvotes: 3
Reputation: 60190
I agree with salva, but my post is going to address the drawing part. Basically, you can add up all lines of the main and the hole polygons together and thereby get a single complex polygon.
The algorithm itself is not very complicted and it is nicely explained in the Polygon Fill Teaching Tool.
Upvotes: 1
Reputation: 10234
Well, if you use the right representation for your polygon you would not need to do anything. Just append the list of edges of the holes to the list of edges of Pa
.
The only consideration you should have is that if some hole vertex or edge can touch Pa edge, you will have to perform some simplification there.
A different problem is rendering that polygon into a bitmap!
Upvotes: 2
Reputation: 1074
You can do like this.
Upvotes: 0