0

If we have two vector data such as polygons or polylines (shown in graph below). How can we get find the overlap and create a new x,y vector data for this new shape? (or simply get the area of the new shape.

import numpy as np
import matplotlib.pyplot as plt

x1 = [10, 20, 40, 50, 50, 40, 20, 10, 10];
y1 = [20, 10, 10, 20, 40, 50, 50, 40, 20];

x2 = [30, 60, 30, 0, 30];
y2 = [40, 50, 70, 60, 40];

fig, ax = plt.subplots()
ax.plot(x1, y1)
ax.plot(x2, y2)
plt.show()

enter image description here

For example, for the above graph where the intersections are, can we get the x,y coordinates/data for this new shape created from the overlap? or get the area of it instead?

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
SGhaleb
  • 979
  • 1
  • 12
  • 30

1 Answers1

2

Constructing the intersection of two polygons is uneasy in the general case. https://en.wikipedia.org/wiki/Vatti_clipping_algorithm

When the polygons are convex, as in your example, you can use the Sutherland-Hodgman algorithm. https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm