Skip to main content
GameDev.net gamedev.net
🔒 Locked

Calculating the intersection area of two polygons

Started by NMO Mar 19, 2007 at 6:36 AM 7 replies 10.7k views
Original Post
NMO
NMO
Hi! As the subject says, I have two abitrary polygons which are intersecting. Both are coplanar too. Now I want to calculate the intersection area of these two polygons. Are there any good approaches for this problem??
alvaro
alvaro
This is a difficult problem. The easier way to solve it is using a third-party library. I have used the GPC library before, and I was satisfied.

NMO
NMO
Thank you for your answer, but is it really as complicated? I would really like to implement my own version. I don't have complicated things like self-intersecting or holes. Aren't there any good approaches??

alvaro
alvaro
The only simple, robust approach I can think of is expressing each polygon as a union of convex polygons, computing the intersections of the convex polygons and putting the results back together. Even this is harder than it looks.

NMO
NMO
Maybe i have found a sultion. When there is an intersection between two polys, at first i compute the intersection polygon(s). The hard thing is to compute the area
of these intersection polygons. To do this I have found an area calculation algorithm according to Gauß. I have tried some examples an all of them worked properly. :)
alvaro
alvaro
Computing the area of an arbitrary polygon is a relatively trivial problem. Calculating the intersection of two arbitrary polygons in a robust manner is much much harder. How do you intend to do that part?
NMO
NMO
Quote:
Computing the area of an arbitrary polygon is a relatively trivial problem.


Yes okay, but that was the main problem.

Quote:
Calculating the intersection of two arbitrary polygons in a robust manner is much much harder. How do you intend to do that part?


I did that already:

Click

And then to calculate the area of this intersecting polygon, I use a Gauß algorithm as mentioned before.
alvaro
alvaro
Area = .5 * abs(x[0]*y[1]-x[1]*y[0] + x[1]*y[2]-x[2]*y[1] + ... + x[n-1]*y[0]-x[0]*y[n-1])


Is that what Gauss said?
NMO
NMO
Yes looks good.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.