inverse distance weighting interpolation
algorithm, c++, interpolation
Solution
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]
but you could replace that with something still decreasing if you want, like `(MIN_DIST + dist[i])/2`.
Problem
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; ``` 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?