Intersection and union of polygons

I have polygons defined with their vertices, and I need to calculate the areas of their union and intersection. The most unpleasant thing is that it is implemented in the Mapping Toolbox, but I can not buy it. Does anyone know how to make a quick algorithm to calculate it? Thank you for your time.

+7
source share
4 answers

I found the intersection points of my polygons and added the vertices that are inside / outside the polygons for the intersection / union problem (check if any of the vertices of the polygon 1 is inside the polygon 2 and vice versa using "inpolygon"). Then all the points were converted into polar coordinates with the center in the middle coordinates of the matrix and sorted by angle, so that now they form a closed closed loop. Knowing this, it is easy to find the intersection / pool area using "polyarea".

0
source

You just need to find the intersection area; the pool area is trivially obtained from this. The PolygonIntersection package from FEX may be useful.

enter image description here

+3
source

I would do the following:

  • Let S be the set of vertices from both polygons.
  • For each edge e 1 in polygon 1
    • For each edge e 2 in polygon 2
      • If e 1 intersects with e 2
        • Add Intersection Point to S
  • Remove all vertices from S that are inside polygon 1 or 2.

The resulting set of vertices should be the union of the polygons.

For the intersection, you simply delete all the vertices in S that are outside of both polygons 1 and 2 (in the third step).

(You can find the intersection point of the point and the "inside-polygon" - in another place ;-)

+1
source

The idea is to split each intersecting edge into four parts and form a new polygon with them. When you want to combine, take the two outer edges. If you want an intersection, take two inner ribs.

0
source

All Articles