A formula to calculate the total overlap area of two polygons?

1.6k Views Asked by At

Suppose I have two polygons that overlap as shown

enter image description here

Given the coordinate for each vertex, is there a formula I can use to find the total area that the polygons share with each other?

Polygon 1
24.99593, -70.98575
24.99411, -70.98534
24.99353, -70.9829
24.99539, -70.98179
24.99671, -70.98414

Polygon 2
24.99585, -70.98294
24.99573, -70.98273
24.99597, -70.9814
24.9949, -70.98157
24.9951, -70.98263
24.99491, -70.98276
24.99474, -70.98241
24.99478, -70.98101
24.99648, -70.98127
24.99683, -70.98223
24.99588, -70.98331
1

There are 1 best solutions below

2
On BEST ANSWER

I am afraid that there is no shortcut to this computation, which is related to the construction of the intersection of the polygons. Anyway, you don't need all the steps.

A possible way is to sort all vertices vertically, and consider all the horizontal slices between two vertices.

In such a slice, both shapes are seen as a set of trapezoids, and computing the area common to these trapezoids is manageable.

This is known as a sweepline algorithm.

enter image description here