Python:在三角形网格中插值 [英] Python: interpolating in a triangular mesh

查看:793
本文介绍了Python:在三角形网格中插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何不错的Pythonic方式在三角形网格中进行插值,还是我需要自己实现?也就是说,给定一个(X,Y)点,我们将其称为P,然后使用一个网格(在(X,Y)处具有Z值的顶点,形成三角形小平面)来估计P处的值.因此,这意味着首先找到包含该点的小平面,然后进行插值-理想情况是比线性地在小平面的顶点之间"(即,考虑到相邻小平面)进行更高阶的插值?

Is there any decent Pythonic way to interpolate in a triangular mesh, or would I need to implement that myself? That is to say, given a (X,Y) point we'll call P, and a mesh (vertices at (X,Y) with value Z, forming triangular facets), estimate the value at P. So that means first find the facet that contains the point, then interpolate - ideally a higher order interpolation than just "linearly between the facet's vertices" (i.e., taking into account the neighboring facets)?

我可以自己实现它,但是如果Python中已有可用的东西....

I could implement it myself, but if there's already something available in Python....

(我检查了scipy.interpolate,但是它的网格"似乎只是正则点网格.这不是网格,它是真正的2D网格;顶点可以位于任何地方.)

(I checked scipy.interpolate, but its "meshes" seem to just be regular point grids. This isn't a grid, it's a true 2D mesh; the vertices can be located anywhere.)

推荐答案

为此,我经常使用matplotlib.tri.这里Xv,Yv是三角形的顶点(或节点),Zv是这些节点处的值:

I often use matplotlib.tri for this purpose. Here Xv,Yv are the vertices (or nodes) of the triangles, and Zv the values at those nodes:

from matplotlib.tri import Triangulation, LinearTriInterpolator, CubicTriInterpolator

#you can add keyword triangles here if you have the triangle array, size [Ntri,3]
triObj = Triangulation(Xv,Yv) 

#linear interpolation
fz = LinearTriInterpolator(triObj,Zv)
Z = fz(X,Y)
#cubic interpolation
fzc = CubicTriInterpolator(triObj,Zv)
Zc = fz(X,Y)

这篇关于Python:在三角形网格中插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆