Calculation of total distance and displacement