C# 具有加权角点的均匀数据网格插值
以下是我目前的情况:C# 具有加权角点的均匀数据网格插值,c#,math,interpolation,C#,Math,Interpolation,以下是我目前的情况: 我有一个由点组成的二维均匀网格,其中每个点都有一个相关的浮点值。 7--2 || 2--1 我可以使用双线性插值在这些点之间插值: public float GetValue(float x, float y, float topLeft, float topRight, float bottomLeft, float bottomRight) { return topLeft*(1-x)*
我有一个由点组成的二维均匀网格,其中每个点都有一个相关的浮点值。
7--2
||代码>
2--1
我可以使用双线性插值在这些点之间插值:
public float GetValue(float x, float y, float topLeft, float topRight,
float bottomLeft, float bottomRight)
{
return topLeft*(1-x)*(1-y) + topRight*x*(1-y) +
bottomLeft*(1-x)*y + bottomRight*x*y;
}
现在,我需要为每个点添加权重,以确定其对周围区域的影响有多大。
例如:如果所有4个点都具有相同的权重值,则这些权重将相互抵消,插值将返回与未加权版本完全相同的值。
现在让我们假设所有点的权重都为1,但左下角的点的权重值为2。在这种情况下,其值对插值的影响将是其他值的两倍,插值将朝着有利于位于左下角的值的方向移动
基本上,我正在尝试实现这样一种方法:
public float GetValue(float x, float y, float topLeftValue, topLeftWeight,
float topRightValue, float topRightWeight,
float bottomLeftValue, float bottomLeftWeight,
float bottomRightValue, float bottomRightWeight)
{
return ?
}
你知道我怎样才能做到这一点吗?是否有考虑加权角点值的方程/算法或双线性插值方法的修改
谢谢你的帮助 为了使事情更简单,假设x=y=0.5
如果所有4个点具有相同的权重值,则返回值应为
return topLeftValue/4 + topRightValue/4 + bottomLeftValue/4 + bottomRightValue/4;
return topLeftValue/5 + topRightValue/5 + bottomLeftValue*2/5 + bottomRightValue/5;
现在,让所有点的权重为1,但左下角的点的权重值为2,返回值应为
return topLeftValue/4 + topRightValue/4 + bottomLeftValue/4 + bottomRightValue/4;
return topLeftValue/5 + topRightValue/5 + bottomLeftValue*2/5 + bottomRightValue/5;
bottomLeftValue的权重通过乘以
4*bottomLeftWeight/(topLeftWeight+topRightWeight+bottomLeftValue+bottomRightWeight)
现在,回到一般情况。
使用上述方法调整每个值的权重。
它将成为
float overallWeight = topLeftWeight + topRightWeight + bottomLeftValue + bottomRightWeight;
返回topLeftValue*(1-x)*(1-y)*(4*topLeftWeight/总重量)
+右上角值*x*(1-y)*(4*右上角重量/总重)
+bottomLeftValue*(1-x)*y*(4*bottomLeftWeight/总重量)
+bottomRightValue*x*y*(4*bottomRightWeight/总重量)
因此,将权重乘以这些值,并在双线性插值中使用它们。