geometry.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:prysm 作者: brandondube 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号