def check(p1, p2, base_array):
''' Checks if the values in the base array fall inside of the triangle
enclosed in the points (p1, p2, (0,0)).
Args:
p1 (`iterable`): iterable containing (x,y) coordinates of a point.
p2 (`iterable`): iterable containing (x,y) coordinates of a point.
base_array (`numpy.ndarray`): a logical array.
Returns:
`numpy.ndarray`: array with True value inside and False value outside bounds
'''
# Create 3D array of indices
idxs = np.indices(base_array.shape)
# ensure points are floats
p1 = p1.astype(float)
p2 = p2.astype(float)
# Calculate max column idx for each row idx based on interpolated line between two points
max_col_idx = (idxs[0] - p1[0]) / (p2[0] - p1[0]) * (p2[1] - p1[1]) + p1[1]
sign = np.sign(p2[0] - p1[0])
return idxs[1] * sign <= max_col_idx * sign
评论列表
文章目录