回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在实现一个双线性插值,如<a href="https://stackoverflow.com/questions/8661537/how-to-perform-bilinear-interpolation-in-python">How to perform bilinear interpolation in Python</a></p>
<p>我有一个点的排序列表,这些点是我规则网格的顶点。你知道吗</p>
<pre><code>[[x1,y1,z1],[x2,y2,z2],[x3,y3,z3],[x4,y4,z4],[x5,y5,z5],...]
</code></pre>
<p>我想在点<code>(x,y)</code>上线性插值。我编写了以下代码</p>
<pre><code>def f(x, y, points):
for i in range(len(points)-1, -1, -1):
if (x>points[i][0])and(y>points[i][1]):
break
try:
pp = [points[i], points[i+1]]
except IndexError:
pp = [points[i], points[i-1]]
for j in range(len(points)):
if (x<points[j][0])and(y<points[j][1]):
break
pp.append(points[j-1])
pp.append(points[j])
(x1, y1, q11), (_x1, y2, q12), (x2, _y1, q21), (_x2, _y2, q22) = pp
return (q11 * (x2 - x) * (y2 - y) +
q21 * (x - x1) * (y2 - y) +
q12 * (x2 - x) * (y - y1) +
q22 * (x - x1) * (y - y1)) / ((x2 - x1) * (y2 - y1))
</code></pre>
<p>但是这个代码在边界上不起作用。我认为这是插值中的常见问题,所以我想知道如何从规则网格中选择(x,y)周围点的最小矩形。你知道吗</p>