Reputation: 109
I have polygons defined with their vertices's, and i need to calculate areas of their union and intersection. The most upsetting thing is that it is implemented in Mapping Toolbox, but i can't buy it. Does anyone knows how to make a fast algorithm to calculate it? Thank you for your time.
Upvotes: 8
Views: 8482
Reputation: 21
The idea is to break every intersect edge into four parts and form a new polygon with these. When you want the union, take the two outer edges. If you want intersection, take the two inner edges.
Upvotes: -1
Reputation: 109
I found intersection points of my polygons and added vertices that are inside/outside polygons for intersection/union task (check if any of vertices of polygon 1 lies inside a polygon 2 and vice versa using 'inpolygon'). Then all points were transformed into polar coordinates with center in the mean coordinates of the matrix and sorted by angle, so that now they form consecutive closed contour. Knowing this it is easy to find intersection/union area using 'polyarea'.
Upvotes: -1
Reputation: 34601
You just need to find the area of intersection ; the area of the union is trivially obtained from that. The PolygonIntersection package from FEX might be useful.
Upvotes: 3
Reputation: 420971
I would do like this:
The resulting set of vertices should make up the union of the polygons.
For the intersection you simply remove all vertices in S that are outside of both polygon 1 and 2 (in the third step).
(You can look up point intersection and "inside-polygon"-checks elsewhere ;-)
Upvotes: 1