Solve a line segment using barycentric coordinates. p = a1 * w1 + a2 * w2 a1 + a2 = 1 The vector from the origin to the closest point on the line is perpendicular to the line. e12 = w2 - w1 dot(p, e) = 0 a1 * dot(w1, e) + a2 * dot(w2, e) = 0 2-by-2 linear system [1 1 ][a1] = [1] [w1.e12 w2.e12][a2] = [0] Define d12_1 = dot(w2, e12) d12_2 = -dot(w1, e12) d12 = d12_1 + d12_2 Solution
source not stored for this graph (policy: none)