离散点求曲率
第一步:离散点拟合函数
第二步:求一阶及二阶导,并带入求曲率公式。
import numpy as np
# x = 离散点x-axis坐标
# y = 离散点y-axis坐标
# x_target = 为拟合的函数采样点(这里是采样点的x-axis值)
# 第一步拟合函数
poly = np.polyfit(x, y, 3) # 拟合n次函数(这里为3次)
poly = np.poly1d(poly)
y_target = poly(x_target)
# 第二步求导
x_t = np.gradient(x_target) # x' 一阶导
xx_t = np.gradient(x_t) # x'' 二阶导
y_t = np.gradient(y_target) # y' 一阶导
yy_t = np.gradient(y_t) # y'' 二阶导
curvature_val = np.abs(xx_t * y_t - x_t * yy_t) / (x_t * x_t + y_t * y_t) ** 1.5 # 求曲率公式