1. 程式人生 > 其它 >判斷點在三角形(多邊形)內部 python

判斷點在三角形(多邊形)內部 python

from shapely import geometry
import matplotlib.pyplot as plt

pts = [(0, 0), (1, 1), (0, 1), (0, 0)]
polygon = geometry.Polygon(pts)

pt = 0.1, 0.2
point = geometry.Point(*pt)

plt.figure(0)
plt.plot([i[0] for i in pts], [i[1] for i in pts])
plt.scatter(*pt)
print(polygon.contains(point))