日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

三次样条python_三次hermit样条插值python

發布時間:2024/3/26 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 三次样条python_三次hermit样条插值python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

{{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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。