Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

intersection and union of polygons

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.

like image 794
Kate Avatar asked Oct 27 '11 12:10

Kate


People also ask

How do you find the intersection of a polygon?

To be able to decide whether two convex polygons are intersecting (touching each other) we can use the Separating Axis Theorem. Essentially: If two convex polygons are not intersecting, there exists a line that passes between them. Such a line only exists if one of the sides of one of the polygons forms such a line.

How do you make a union polygon?

On the Edit Polygons menu, click Merge. Select two adjacent polygons. The new polygon has the attributes of the last polygon selected.

What is the point of intersection of a polygon?

What is the point of intersection of two sides of a polygon? Hi Tyler. Formally, mathematicians call them vertices (plural for vertex). But more casually, we just call them corners.

What is the difference between a union and an intersection?

What is the difference between union and intersection? A union of sets produces a new set containing each element present in the original sets. An intersection of sets produces a new set that contains only the elements that the original sets have in common.


2 Answers

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.

enter image description here

like image 95
Jacob Avatar answered Oct 21 '22 09:10

Jacob


I would do like this:

  1. Let S be the set of vertices from both polygons.
  2. For each edge e1 in polygon 1
    1. For each edge e2 in polygon 2
      1. If e1 intersects with e2
        1. Add the intersection point to S
  3. Remove all vertices in S that are inside polygon 1 or 2.

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 ;-)

  • Intersection point of two lines
  • Determining if a point lies on the interior of a polygon
like image 29
aioobe Avatar answered Oct 21 '22 08:10

aioobe