【问题标题】:Smoothing/interpolation of 3D potential field in PythonPython中3D势场的平滑/插值
【发布时间】:2020-03-11 16:41:30
【问题描述】:

我正在处理有障碍物的配置空间中的路径规划问题。我用一个势场对其进行建模,其中障碍物是从表面出现的峰。我想插入这些峰值,以便更平滑地表示障碍物。我尝试使用 scipy griddata 函数,但它给了我这个:(见第二张图片)。请问有人有想法吗?

这是我的代码:

#map
nx = 40
ny = 40
x = np.linspace(0,5,nx)
y = np.linspace(0,5,ny)
X,Y = np.meshgrid(x,y)

#data to plot
U = np.zeros((nx,ny))
points = []
for i in range(nx):
    for j in range(ny):
        U[i][j] = potential(X[i][j],Y[i][j],gx,gy,obstacle,mu)
        points.append([i,j])

#interpolation
xnew ,ynew = np.linspace(0,5,2*nx), np.linspace(0,5,2*ny)
Xnew, Ynew = np.meshgrid(xnew,ynew)
values = np.reshape(U,(1600,))
Z = griddata(points, values, (Xnew, Ynew), method='linear')

#plot
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(Xnew, Ynew, Z, cmap=cm.coolwarm,linewidth=0, antialiased=False)
fig2 = plt.figure()
ax = fig2.gca(projection='3d')
surf = ax.plot_surface(X, Y, U, cmap=cm.coolwarm,linewidth=0, antialiased=False)
fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

【问题讨论】:

    标签: python numpy multidimensional-array scipy 3d


    【解决方案1】:

    如果您确信这些数据点不是异常值...您可以使用 SciPy lib 内置函数的插值函数。此链接下提供了示例:

    [3d 样条插值][1] Spline interpolation in 3D in python

    请注意,SciPy 非常慢。引用第 2 条下的回复,基于一些随机数据集 (512x512x110) 差异可能很大:

    SciPy的解决方案:982ms;你的 cython 解决方案:24.7ms

    Python 3D interpolation speedup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多