Posts

Showing posts with the label Coordinates

Calculating Coordinates Given A Bearing And A Distance

Answer : It seems like these are the issues in your code: You need to convert lat1 and lon1 to radians before calling your function. You may be scaling radialDistance incorrectly. Testing a floating-point number for equality is dangerous. Two numbers that are equal after exact arithmetic might not be exactly equal after floating-point arithmetic. Thus abs(x-y) < threshold is safer than x == y for testing two floating-point numbers x and y for equality. I think you want to convert lat and lon from radians to degrees. Here is my implementation of your code in Python: #!/usr/bin/env python from math import asin,cos,pi,sin rEarth = 6371.01 # Earth's average radius in km epsilon = 0.000001 # threshold for floating-point equality def deg2rad(angle): return angle*pi/180 def rad2deg(angle): return angle*180/pi def pointRadialDistance(lat1, lon1, bearing, distance): """ Return final coordinates (lat2,lon2) [in degrees] given...