如何在python中栅格化多边形?例如,我有这个多边形:
[(20,13),(21,12),(20,12),(19,12),(21,13)]
这是一个边框,我需要找到它内部的所有点(瓷砖)。如何在没有任何外部包的情况下使用python做到这一点? 感谢。
答案 0 :(得分:0)
快捷方式:
def raster(poly):
for index in range(len(poly) - 1):
t1 = poly[index]
t2 = poly[index + 1]
xdef = t1[0] - t2[0]
ydef = t1[1] - t2[1]
if abs(xdef) > 1:
lo = min(t1[0], t2[0])
hi = max(t1[0], t2[0])
j = lo
while(j <= hi):
new = (j, t1[1])
poly.append(new)
j += 1
if abs(ydef) > 1:
lo = min(t1[1], t2[1])
hi = max(t1[1], t2[1])
j = lo
while(j <= hi):
new = (t1[0], j)
poly.append(new)
j += 1
return poly