calculates angles and distance