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.
<
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])