Distance measurement and calculation