{{em}在这里举例说明了{em}在一些给定的维数之间的导数的用法。在import numpy as np

from scipy import interpolate

def sampleCubicSplinesWithDerivative(points, tangents, resolution):

'''

Compute and sample the cubic splines for a set of input points with

optional information about the tangent (direction AND magnitude). The

splines are parametrized along the traverse line (piecewise linear), with

the resolution being the step size of the parametrization parameter.

The resulting samples have NOT an equidistant spacing.

Arguments: points: a list of n-dimensional points

tangents: a list of tangents

resolution: parametrization step size

Returns: samples

Notes: Lists points and tangents must have equal length. In case a tangent

is not specified for a point, just pass None. For example:

points = [[0,0], [1,1], [2,0]]

tangents = [[1,1], None, [1,-1]]

'''

resolution = float(resolution)

points = np.asarray(points)

nPoints, dim = points.shape

# Parametrization parameter s.

dp = np.diff(points, axis=0) # difference between points

dp = np.linalg.norm(dp, axis=1) # distance between points

d = np.cumsum(dp) # cumsum along the segments

d = np.hstack([[0],d]) # add distance from first point

l = d[-1] # length of point sequence

nSamples = int(l/resolution) # number of samples

s,r = np.linspace(0,l,nSamples,retstep=True) # sample parameter and step

# Bring points and (optional) tangent information into correct format.

assert(len(points) == len(tangents))

data = np.empty([nPoints, dim], dtype=object)

for i,p in enumerate(points):

t = tangents[i]

# Either tangent is None or has the same

# number of dimensions as the point p.

assert(t is None or len(t)==dim)

fuse = list(zip(p,t) if t is not None else zip(p,))

data[i,:] = fuse

# Compute splines per dimension separately.

samples = np.zeros([nSamples, dim])

for i in range(dim):

poly = interpolate.BPoly.from_derivatives(d, data[:,i])

samples[:,i] = poly(s)

return samples

为了演示此函数的用法,我们指定点和切线。该示例进一步演示了切线的“幅值”更改时的效果。在

^{pr2}$

结果如下:

有三点需要注意:以下内容也适用于两个以上的维度。在

样本之间的间距不是固定的。实现等距采样的一种简单方法是在返回的samples之间进行线性插值,正如在this post中所讨论的那样。在

切线的指定是可选的,但是BPoly.from_derivatives不能确保在此位置的样条曲线之间的平滑过渡。例如,如果上述示例中的tangents[1]设置为None,sampleCubicSplinesWithDerivative(points, tangents, resolution),则结果如下:

三次样条python_三次hermit样条插值python相关推荐

  1. 第三百三十八节,Python分布式爬虫打造搜索引擎Scrapy精讲—深度优先与广度优先原理...

    第三百三十八节,Python分布式爬虫打造搜索引擎Scrapy精讲-深度优先与广度优先原理 网站树形结构 深度优先 是从左到右深度进行爬取的,以深度为准则从左到右的执行(递归方式实现)Scrapy默认 ...

  2. java和python的web自动化有什么区别-三分钟看懂Python和Java的区别

    随着人工智能的火爆,Python和Java一直在各种流行编程语言中名列前茅.其实Java和Python有些相似,因为很多编程语言之间是互通的.Java现在还是第一,不知道Python未来会不会超越Ja ...

  3. python和java一样吗-三分钟看懂Python和Java的区别

    随着人工智能的火爆,Python和Java一直在各种流行编程语言中名列前茅.其实Java和Python有些相似,因为很多编程语言之间是互通的.Java现在还是第一,不知道Python未来会不会超越Ja ...

  4. python中两个集合的运算并交补_三种方式实现 Python 中的集合的交、并、补运算...

    文章目录 三种方式实现 Python 中的集合的交.并.补运算 一 背景 集合这个概念在我们高中阶段就有所了解,毕业已多年,我们一起回顾一下几个集合相关的基本概念吧? 集合是指具有某种特定性质的具体的 ...

  5. python中特殊变量-python list每三个分成一组python中星号变量的几种特殊用法

    在Python中星号除了用于乘法数值运算和幂运算外,还有一种特殊的用法"在变量前添加单个星号或两个星号",实现多参数的传入或变量的拆解,本文将详细介绍"星号参数" ...

  6. python和java的区别-三分钟看懂Python和Java的区别

    随着人工智能的火爆,Python和Java一直在各种流行编程语言中名列前茅.其实Java和Python有些相似,因为很多编程语言之间是互通的.Java现在还是第一,不知道Python未来会不会超越Ja ...

  7. 三位水仙花数python代码

    三位水仙花数python代码 #水仙花数:其各位数字立方和等于该数本身. print("水仙花数有:") for i in range(100,1000):bw=i//100sw= ...

  8. PB协议(三)Protobuf的Python开发教程

    本系列文章目录 展开/收起 PB协议(一)什么是Pb协议(Protobuf),Pb协议如何使用,PB协议的数据类型 PB协议(二)Protobuf的PHP开发教程 PB协议(三)Protobuf的Py ...

  9. 计算机大三了只会python可以去名企实习吗?如何找python实习

    知乎上有人问"软工大三下了,只会python,还没找到实习怎么办?",关于这个问题,网友的答复很是耿直,比如 网友1的答复是:找工作了才只会个简单的django项目,人家公司招人是 ...

最新文章

  1. core data 学习笔记
  2. eBay的Elasticsearch性能调优实践
  3. python远程桌面控制_手把手教你如何用Pycharm2020.1.1配置远程连接的详细步骤
  4. 深入理解Sqlserver索引
  5. javascript数组去重方法汇总
  6. Download a image 图片另存为
  7. 那年我学过的Spring笔记
  8. 基于matlab的图像拼接论文,基于MATLAB的图像拼接算法实现研究
  9. PHP 中移除微信emoji表情
  10. 多开 android模拟器,安卓模拟器如何多开窗口保证游戏不封号
  11. 单像空间后方交会的程序实现
  12. 华为方舟编译器开源官网正式上线,并首次开放了框架源码!
  13. MYSQL JDBC快速查询响应的方法,快速返回机制的实现
  14. TCP 协议(序号和确认号)
  15. IOS中__bridge,__bridge_retained和__bridge_transfer理解
  16. 使用Trinity 软件进行拼接(无参转录组)
  17. VBA调用系统调色板
  18. 【科普】基础教程系列之装系统篇
  19. 【Kettle】 Javascript脚本组件
  20. Xshell中vim编辑时,数字小键盘不能用、查看文件乱码解决办法

热门文章

  1. 《惢客创业日记》2019.01.16(周三) 为什么很多明星的人设都崩塌了?
  2. selenium 学习、工作 记录,附常见异常和工具方法
  3. FFmpeg入门详解之7:MediaInfo简介
  4. 你能向我解释范畴 论里的monad吗?
  5. routeros配置ipv6问题记录
  6. xp如何查看计算机配置文件,Windows XP如何修改用户配置文件默认位置
  7. 程序员面试时如何优雅地自我介绍?
  8. 工程力学(9)—轴向拉伸和压缩一
  9. cakephp bake
  10. Spring 源码分析 (一)——迈向 Spring 之路