Add an euclidean distance function for calcs

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