# Approximating a fourth point with a weighted average between three points?

Given three points, how would one approximate the best positive weights (u, v, w) such that u+v+w = 1, and that the distance between the new u*p0 + v*p1 + w*p2 from p3 is minimal?

Basically, the player's unit is between several enemy bases in (3d) space and it is easy to tell which is closest or even find the "weights" between two bases (t, 1-t) to describe the relative how the players influence is spread. How does one find the optimal weights for three or more surrounding points?

• Why do you want to find specifically points with u+v+w = 1, when you are interested in the distance/influence? Why not just compute/compare distances to said 3 points? – wondra Nov 2 '16 at 17:03
• This is just chaining together two common operations: 1) find the closest point to p3 on the plane containing p0p1p2 (hint: find the normal n to that plane, then your in-plane point q = p3 - n * dot(n, p3 - p0)) 2) find the Barycentric coordinates of q within the triangle p0p1p2 – DMGregory Nov 2 '16 at 17:16