math calculation of distances