Ive been using the geopy package , which does a great job, however some of the results i get are inconsistant or come with a relatively large displacement, i suspect that the problem resides with my bearing calculation:
def gb(x,y,center_x,center_y):
dx=x-center_x
dy=y-center_y
if ((dy>=0)and((dx>0)or(dx<0))):
return math.degrees(math.atan2(dy,dx))
elif (dy<=0)and((dx>0)or (dx<0)):
return (math.degrees(math.atan2(dy,dx))+360)
else:
return (math.degrees(math.atan2(dy,dx))+360)%360
I need to calculate the bearing, s.t. center_x and center_y are the pivot. afterwards i use geopy to reverse engineer the gps coordinate:
latlon = VincentyDistance(miles=dist).destination(Point(lat1, lon1), bearing)
Can anyone point me to what might i be doing wrong?
Not showing an example of your "inconsistant or come with a relatively large displacement" results nor your expected results; consequently answerers must rely on guesswork.
Not saying what units your input (x, y, etc) is measured in, and how you get the
dist
used in thedestination
calculation. I'm assuming (in calculatingbearing2
below) that positive x is easting in miles and positive y is northing in miles. It would help greatly if you were to edit your question to fix (1) and (2).A coding style that's not very conducive to making folk want to read it ... have a look through this.
In school trigonometry, angles are measured anticlockwise from the X axis (East). In navigation, bearings are measured clockwise from the Y axis (North). See code below. For an example of bearing in use, follow this link, scroll down to the "Destination point given distance and bearing from start point" section, notice that the example is talking about bearings of about 96 or 97 degrees, then click on "view map" and you will notice that the heading is slightly south of east (east being 90 degrees).
Code:
Output: