python计算二维平面的曲线的曲率

曲率用来描述一段曲线像一个圆的程度,曲率的倒数就是曲率半径

  • 曲率半径越大,曲率越小,说明曲线越平滑
  • 曲率半径越小,曲率越大,说明曲线越弯

曲率半径的百度百科网址:https://baike.baidu.com/item/%E6%9B%B2%E7%8E%87%E5%8D%8A%E5%BE%84/2036643?fr=aladdin

计算曲率的主要方法如下:

def calculate_curvature(x_value: np.ndarray, y_value: np.ndarray):
    """计算曲率"""
    x_t = np.gradient(x_value)
    y_t = np.gradient(y_value)
    xx_t = np.gradient(x_t)
    yy_t = np.gradient(y_t)
    curvature_val = np.abs(xx_t * y_t - x_t * yy_t) / (x_t * x_t + y_t * y_t) ** 1.5
    return curvature_val

示例

import numpy as np


def calculate_curvature(x_value: np.ndarray, y_value: np.ndarray):
    """计算曲率"""
    x_t = np.gradient(x_value)
    y_t = np.gradient(y_value)
    xx_t = np.gradient(x_t)
    yy_t = np.gradient(y_t)
    curvature_val = np.abs(xx_t * y_t - x_t * yy_t) / (x_t * x_t + y_t * y_t) ** 1.5
    return curvature_val


if __name__ == '__main__':
    array = np.random.randint(0, 20, size=(2, 50))
    x = array[0]
    y = array[1]
    cur = calculate_curvature(x, y)
    print(cur)

你可能感兴趣的:(python,python)