Python中的多边形光栅化
如何在python中栅格化多边形?例如,我有一个多边形: [(20,13)、(21,12)、(20,12)、(19,12)、(21,13)] 这是一个边界,我需要找到它里面的所有点(瓷砖)。在没有任何外部包的情况下如何使用python? 谢谢。捷径:Python中的多边形光栅化,python,polygon,rasterizing,Python,Polygon,Rasterizing,如何在python中栅格化多边形?例如,我有一个多边形: [(20,13)、(21,12)、(20,12)、(19,12)、(21,13)] 这是一个边界,我需要找到它里面的所有点(瓷砖)。在没有任何外部包的情况下如何使用python? 谢谢。捷径: def raster(poly): for index in range(len(poly) - 1): t1 = poly[index] t2 = poly[index + 1] xdef
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
def光栅(多边形):
对于范围内的索引(len(poly)-1):
t1=多边形[索引]
t2=多边形[指数+1]
xdef=t1[0]-t2[0]
ydef=t1[1]-t2[1]
如果abs(xdef)>1:
lo=min(t1[0],t2[0])
hi=最大值(t1[0],t2[0])
j=lo
而(j 1:
lo=min(t1[1],t2[1])
hi=最大值(t1[1],t2[1])
j=lo
while(j