Fastest way to get all the points between two (X,Y) coordinates in python

后端 未结 3 845
星月不相逢
星月不相逢 2020-12-16 07:58

So I have a shapely LineString:

print np.round(shapely_intersecting_lines.coords).astype(np.int) 
>>> array([[ 1520, -1140         


        
3条回答
  •  有刺的猬
    2020-12-16 08:40

    Here's Bresenhams line algorithm as a generator. If you want a list just call list() on the output:

    def line(x0, y0, x1, y1):
        deltax = x1-x0
        dxsign = int(abs(deltax)/deltax)
        deltay = y1-y0
        dysign = int(abs(deltay)/deltay)
        deltaerr = abs(deltay/deltax)
        error = 0
        y = y0
        for x in range(x0, x1, dxsign):
            yield x, y
            error = error + deltaerr
            while error >= 0.5:
                y += dysign
                error -= 1
        yield x1, y1
    

提交回复
热议问题