system
April 22, 2013, 12:57am
1
Greetings!
I am currently trying to code a function that when given two GPS coordinates, it will return the Great Circle Bearing needed to get from Point A to Point B. The current code for my test coordinates returns 41degrees, when most other websites confirm the bearing to be around 154 degrees.
Catalina 25, Catalina 250, and Capri International Association, membership and information about the sailboat.
This web site is made possible by Catalina 25, Catalina 250, and Capri 25 sailboat owners who have joined this
International ...
I am wondering if someone could help me with my code. Thanks!
float bearingCalc;
flon1 = 38.430767 * (PI/180);
flat1 = -122.756332 * (PI/180);
flon2 = 38.231410 * (PI/180);
flat2 = -122.634388 * (PI/180);
float dlat = (flat2 - flat1);
float dlon = (flon2 - flon1);
float y = sin(dlon)*cos(flat2);
float x = (cos(flat1)*sin(flat2)) - (sin(flat1)*cos(flat2)*cos(dlon));
bearingCalc = atan2 (y,x);
bearingCalc = bearingCalc * (180/PI);
if(bearingCalc<=0){
bearingCalc=360-bearingCalc;
}
Serial.println(bearingCalc);
return bearingCalc;
system
April 22, 2013, 1:18am
2
I don't recognise that as the haversine formula but I haven't tried to follow your calculation through to see whether I believe it. However, this part at the end caught my eye:
if(bearingCalc<=0){
bearingCalc=360-bearingCalc;
}
I guess you're trying to normalise the bearing, but that's not what this does.
Lots of A few subjects started on this matter lately.
(I wonder...)
(I wonder...)
Hmmm. Coincidence?
Anyway:
@OP
flon1 = 38.430767 * (PI/180);
flat1 = -122.756332 * (PI/180);
flon2 = 38.231410 * (PI/180);
flat2 = -122.634388 * (PI/180);
These aren't right. You've got the lats and longs mixed up. latitudes can't be -122!
Pete
system
April 22, 2013, 3:31am
5
el_supremo:
(I wonder...)
Hmmm. Coincidence?
Anyway:
@OP
flon1 = 38.430767 * (PI/180);
flat1 = -122.756332 * (PI/180);
flon2 = 38.231410 * (PI/180);
flat2 = -122.634388 * (PI/180);
These aren't right. You've got the lats and longs mixed up. latitudes can't be -122!
Pete
Wow, I didn't notice that at all. That appears to have fixed my bearing problem.
Thank you for your help!