点集的曲率

Curvature of set of points

data file

import matplotlib.pylab as plt
import numpy as np

#initial data
data=np.loadtxt('profile_nonoisebigd02.txt')
x=data[:,0]
y=data[:,1]

#first derivatives 
dx= np.gradient(data[:,0])
dy = np.gradient(data[:,1])

#second derivatives 
d2x = np.gradient(dx)
d2y = np.gradient(dy)

#calculation of curvature from the typical formula
curvature = np.abs(dx * d2y - d2x * dy) / (dx * dx + dy * dy)**1.5

任何人都可以帮我解决曲率哪里出了问题吗? 这组点给了我一条抛物线,但曲率不是我所期望的。

看来你的数据还不够流畅;我使用 pandas 通过滚动方式替换 x、y、dx、dy、d2x、d2y 和曲率,以获得不同的值 window 大小。随着 window 大小的增加,曲率开始看起来越来越像您期望看到的平滑抛物线(图例给出 window 大小):

作为参考,这里是您的原始数据图:

用于创建平滑帧的代码:

def get_smooth(smoothing=10, return_df=False):
    data=np.loadtxt('profile_nonoisebigd02.txt')

    if return_df:
        return pd.DataFrame(data)

    df = pd.DataFrame(data).sort_values(by=0).reset_index(drop=True).rolling(smoothing).mean().dropna()

    # first derivatives
    df['dx'] = np.gradient(df[0])
    df['dy'] = np.gradient(df[1])

    df['dx'] = df.dx.rolling(smoothing, center=True).mean()
    df['dy'] = df.dy.rolling(smoothing, center=True).mean()

    # second derivatives
    df['d2x'] = np.gradient(df.dx)
    df['d2y'] = np.gradient(df.dy)

    df['d2x'] = df.d2x.rolling(smoothing, center=True).mean()
    df['d2y'] = df.d2y.rolling(smoothing, center=True).mean()


    # calculation of curvature from the typical formula
    df['curvature'] = df.eval('abs(dx * d2y - d2x * dy) / (dx * dx + dy * dy) ** 1.5')
    # mask = curvature < 100

    df['curvature'] = df.curvature.rolling(smoothing, center=True).mean()

    df.dropna(inplace=True)
    return df[0], df.curvature