functions to calc distance and find if in range