calc distance for dynamically