Python 中二维凸包的偏心率

Eccentricity of a 2D convex hull in Python

如何计算 Python 中二维凸包的 eccentricity

偏心率:椭圆(或闭合形状)偏离圆度的参数,取值范围为0(圆)到1(线)。

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

轴的端点被视为每个轴上的最小值和最大值点。使用 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