曲线的曲率介绍

曲线的曲率(curvature):就是针对曲线上某个点的切线方向角对弧长的转动率,通过微分来定义,表明曲线偏离直线的程度。数学上表明曲线在某一点的弯曲程度的数值。

曲率越大,表示曲线的弯曲程度越大。曲率的倒数就是曲率半径。

  • 曲线的两端的端点是没有曲率可谈的,和滑动平均类似,曲率的求解方式和滑动平均有类似之处,
  • 曲率达到一定范围,才认为其有拐点

平滑方法介绍

1. 环境及模块介绍:

  1. 环境
  • 编译器:python 3.x
  1. 需要使用的模块:
  • numpy
  • matplotlib
  • scipy

环境安装

# 在终端中输入
pip install numpy -i https://pypi.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tsinghua.edu.cn/simple
pip install scipy -i https://pypi.tsinghua.edu.cn/simple

2. 代码示例

  1. 随机生成10个坐标点
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
import matplotlib

matplotlib.use('TkAgg')

x = np.linspace(0, 20, 10)
y = np.random.uniform(-10, 10, 10)
  1. 先画出散点图看看
plt.figure(figsize=(10, 5), dpi=100)
# plt.plot(x, y)
plt.scatter(x, y, c="red")
plt.grid(True)
plt.show()

在这里插入图片描述
3. 折线图

plt.figure(figsize=(10, 5), dpi=100)
plt.plot(x, y)
plt.scatter(x, y, c="red")
plt.grid(True)
plt.show()

在这里插入图片描述
4. 平滑曲线

x_smooth = np.linspace(x.min(), x.max(), 400)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.figure(figsize=(10, 5), dpi=100)
plt.grid(True)
plt.plot(x_smooth, y_smooth)
plt.show()

在这里插入图片描述

  1. 对比(折线与平滑曲线)
x_smooth = np.linspace(x.min(), x.max(), 400)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.figure(figsize=(10, 5), dpi=100)
plt.grid(True)
plt.plot(x_smooth, y_smooth)
plt.plot(x, y)
plt.scatter(x, y, c="red")
plt.show()

在这里插入图片描述

3. 整体代码

# -*- coding:utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
import matplotlib

matplotlib.use('TkAgg')

x = np.linspace(0, 20, 10)
y = np.random.uniform(-10, 10, 10)

plt.figure(figsize=(10, 5), dpi=100)
plt.scatter(x, y, c="red")
plt.grid(True)
plt.show()

plt.figure(figsize=(10, 5), dpi=100)
plt.plot(x, y)
plt.scatter(x, y, c="red")
plt.grid(True)
plt.show()

x_smooth = np.linspace(x.min(), x.max(), 400)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.figure(figsize=(10, 5), dpi=100)
plt.grid(True)
plt.plot(x_smooth, y_smooth)
plt.show()

x_smooth = np.linspace(x.min(), x.max(), 400)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.figure(figsize=(10, 5), dpi=100)
plt.grid(True)
plt.plot(x_smooth, y_smooth)
plt.plot(x, y)
plt.scatter(x, y, c="red")
plt.show()

print('over...')
Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐