The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.
struct Point
{
double x;
double y;
double value;
}
double InverseDistanceWeight(Point &target, Point allPoints[], int count)
{
double total = 0;
double sum = 0;
double distance, weight, value;
for (int i = 0; i < count; ++i)
{
// Euclidean distance
distance = sqrt(pow(target.x - allPoints[i].x, 2) + pow(target.y - allPoints[i].y, 2));
weight = 1/distance; // the weighting function
value = weight * allPoints[i].value; // the adjusted value
total += value; // sum it all up
sum += weight;
}
// get the weighted average
target.value = total/sum;
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.