【问题标题】:Polygon Rasterization in PythonPython中的多边形光栅化
【发布时间】:2014-02-15 22:34:57
【问题描述】:

如何在 python 中栅格化多边形?例如我有这个多边形:

[(20, 13), (21, 12), (20, 12), (19, 12), (21, 13)]

这是一个边界,我需要找到其中的所有点(图块)。如何在没有任何外部包的情况下使用 python 做到这一点? 谢谢。

【问题讨论】:

    标签: python polygon rasterizing


    【解决方案1】:

    快捷方式:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2018-08-25
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多