I have a problem which draws my back in some project for some time now.
I’m basically looking to trap a polygon using x, y points drawn by some script I’ve written. lat, lon are the center GPS cords of the polygon and I’m looking for its surrounding polygon.
here is a part of my code in python:
JavaScript
x
5
1
def getcords(lat, lon, dr, bearing):
2
lat2=asin(sin(lat)*cos(dr)+cos(lat)*sin(dr)*cos(bearing))
3
lon2=lon+atan2(sin(bearing)*sin(dr)*cos(lat),cos(dr)-sin(lat)*sin(lat2))
4
return [lat2,lon2]
5
my input goes like this:
- lat, lon – are given in decimal degrees.
- dr – is the angular computed by dividing the distance in miles by the earth’s -radius(=3958.82)
- bearing – between 0-360 degrees.
However for the input:
JavaScript
1
2
1
getcorsds1(42.189275, -76.85823, 0.5/3958.82, 30)
2
I get output: [-1.3485899508698462, -76.8576637627568]
, however [42.2516666666667, -76.8097222222222]
is the right answer.
as for the angular distance, I calculate it simply by dividing the distance in miles by the earth’s radius(=3958.82).
anybody?
Advertisement
Answer
Why don’t you use nice libraries?
JavaScript
1
6
1
from geopy import Point
2
from geopy.distance import distance, VincentyDistance
3
4
# given: lat1, lon1, bearing, distMiles
5
lat2, lon2 = VincentyDistance(miles=distMiles).destination(Point(lat1, lon1), bearing)
6
For lat1, lon1, distMiles, bearing = 42.189275,-76.85823, 0.5, 30 it returns 42.1955489, -76.853359.