假设有两个多边形 p1 和 p2,其中 p2 完全在 p1 内部
p1 = [(0, 10), (10, 10), (10, 0), (0, 0)]
p2 = [(2, 6), (6, 6), (6, 2), (2, 2)]
degree_of_contact = 0
xyarrays = [p1,p2]
p1_degree_of_contact = 0
for x,y in xyarrays[0]:
if point_inside_polygon(x,y,xyarrays[1]):
p1_degree_of_contact += 1
p2_degree_of_contact = 0
for x,y in xyarrays[1]:
if point_inside_polygon(x,y,xyarrays[0]):
p2_degree_of_contact += 1
degree_of_contact = p1_degree_of_contact + p2_degree_of_contact
where 多边形内的点 https://stackoverflow.com/questions/15179405/python-debug-a-point-inside-polygon-function是确定一个点是否在多边形内部(True,False 否则),
其中 poly 是包含多边形顶点坐标的 (x,y) 对列表。该算法称为“光线投射法”
我希望以一种优雅的方式(行编码保存)将两个循环组合在一起。