Python中2D凸包的偏心率

时间:2018-09-19 13:11:02

标签: python convex-hull feature-descriptor

如何在Python中计算2D凸包的eccentricity

偏心率:椭圆(或闭合形状)的参数,指示其与圆度的偏差,其值的范围从0(圆形)到1(直线)。

1 个答案:

答案 0 :(得分:1)

好吧,对于仍然希望看到这个问题的答案的人:如果我们假设闭合形状是椭圆形或类似于椭圆形,则eccentricity被定义为sqrt(square(major_axis_length/2)-square(minor_axis_length/2)),其中长轴和短轴如图所示。 enter image description here

将轴的端点作为沿每个轴的最小和最大值。通过4个示例地理点(这些也可以是笛卡尔坐标),我们可以编写如下内容:

import numpy as np
from scipy.spatial.distance import euclidean

points = np.array([[50.6636778,5.0939791], [50.7674881,5.4663611], [50.94594, 5.48977], [51.0380754,5.4012648]])

small_latwise = np.min(points[points[:, 0] == np.min(points[:, 0])], 0)
small_lonwise = np.min(points[points[:, 1] == np.min(points[:, 1])], 0)
big_latwise = np.max(points[points[:, 0] == np.max(points[:, 0])], 0)
big_lonwise = np.max(points[points[:, 1] == np.max(points[:, 1])], 0)
distance_lat = euclidean(big_latwise, small_latwise)
distance_lon = euclidean(big_lonwise, small_lonwise)
if distance_lat >= distance_lon:
    major_axis_length = distance_lat
    minor_axis_length = distance_lon
else:
    major_axis_length = distance_lon
    minor_axis_length = distance_lat
a = major_axis_length/2
b = minor_axis_length/2
ecc = np.sqrt(np.square(a)-np.square(b))/a
print(ecc)

哪个产生0.0854194406287