Generating a filled polygon inside a numpy array

后端 未结 2 1119
难免孤独
难免孤独 2021-01-15 02:47

I\'m looking for a way to \'draw\' a filled polygon into a numpy array based upon a set of polygon vertices. I\'d prefer to use as few external libraries as possible.

<
2条回答
  •  伪装坚强ぢ
    2021-01-15 03:08

    I found one bug in @schoolie response and stackoverflow do not allow add multi line code snippets in comments the problem is when p1[0] == p2[0]. My suggestion of update in function check:

    if p1[0] == p2[0]:
        max_col_idx = (idxs[0] - p1[0]) * idxs.shape[1]
        sign = np.sign(p2[1] - p1[1])
    else:
        max_col_idx = (idxs[0] - p1[0]) / (p2[0] - p1[0]) * (p2[1] - p1[1]) + p1[1]
        sign = np.sign(p2[0] - p1[0])
    

提交回复
热议问题