Calculation of distances and angles