Add a euclidean distance function for calcs

Changed the formula with a more accurate one after some manual testing.

ping @pedrogimenez