Calculation of angles and distances