Formula to calculate speed and distance