With barycenter 𝐺, key identity:

𝑚𝑘𝑀𝑋𝑘2=(𝑚𝑘)𝑀𝐺2+𝑚𝑘𝐺𝑋𝑘2

Sometimes 𝑀 is constrained to a plane. In that case, the projection of 𝐺 down the plane minimizes the sum.

References