# 点到两个端点所确定的直线的距离 classic formula is:
# # d = [(x2-x1)*(y1-y)-(x1-x)*(y2-y1)] / sqrt((x2-x1)**2 + (y2-y1)**2)
#
xD = (x2 - x1)
yD = (y2 - y1)
detaX = x1 - X
detaY = y1 - Y
norm2 = sqrt(xD ** 2 + yD ** 2) # 注意norm2是一个数而不是numpy数组,因为xD, yD都是一个数。单个数字运算math比numpy快
b = thre
dist = xD * detaY - detaX * yD # 常数与numpy数组(X,Y是坐标数组)的运算,broadcast
dist /= norm2
dist = np.abs(dist)
ratiox = np.abs(detaX / (xD + 1e-8))
ratioy = np.abs(detaY / (yD + 1e-8))
ratio = np.where(ratiox < ratioy, ratiox, ratioy)
ratio = np.where(ratio > 1, 1, ratio) # 不用 np.ones_like(ratio)也可以正常运行,并且会快一点点
ratio = np.where(ratio > 0.5, 1 - ratio, ratio)
oncurve_dist = b * np.sqrt(1 - np.square(ratio * 2)) # oncurve_dist计算的是椭圆边界上的点到长轴的垂直距离
sigma = thre # todo: sigma of PAF 对于PAF的分布,设其标准差为多少最合适呢
guass_dist[dist >= b] = 0
return guass_dist
判断平面内一个点 是否在两个点所确定的长轴椭圆内
猜你喜欢
转载自blog.csdn.net/xiaojiajia007/article/details/80080793
今日推荐
周排行