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.
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".
You just need to find the intersection area; the pool area is trivially obtained from this. The PolygonIntersection package from FEX may be useful.
I would do the following:
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 ;-)
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.