Question: are you minimizing the sum of the distances? If so, there is a very elegant solution of this problem in this book, pages 6-7. If you do the "Search Inside This Book", and search for "drilling three holes", you will at least get page 6, which contains most of the derivation. The mathematical derivation is on page 7.