问题描述
我想计算重量的距离的东西互惠如反距离加权插值。
I would like to compute a weight as reciprocal of a distance for something like inverse distance weighting interpolation.
double wgt = 0, wgt_tmp, result = 0;
for (int i = 0; i < num; i++) {
wgt_tmp = 1.0/dist[i];
wgt += wgt_tmp;
result += wgt_tmp * values[i];
}
results /= wgt;
不过的距离可以 0
,我需要做的重量适合计算。如果只有一个距离测距[I]
是 0
,我想它的对应值值[I]
是主导。如果有几个距离是 0
,我想有自己的价值观为贡献同样的结果。此外,即使测距[I]
不为零,但非常小,我想有一个合理的标准来检查和处理。任何想法如何实现它?
However the distance can be 0
and I need to make the weight suitable for computation. If there is only one distance dist[i]
is 0
, I would like its corresponding value values[i]
to be dominant. If there are several distances are 0
, I would like to have their values to contribute equally to the result. Also even if dist[i]
is not zero but very small, I would like to have a reasonable criterion to check it and deal with it. Any idea how to implement it?
推荐答案
我不明白,除了分段任何方式 - 你需要一个不同的功能比小距离倒数距离。最简单的事情是只砍掉顶部:
I don't see any way besides piecewise - you need a different function than reciprocal distance for small distances. The simplest thing would be to just chop off the top:
modified_dist[i] = dist[i] < MIN_DIST ? MIN_DIST : dist[i]
但你可以替换的东西仍然在下降,如果你想,像(MIN_DIST + DIST [I])/ 2
。
这篇关于反距离加权插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!