Hey Guys.
I'm having a hard time wrapping my head around some Trigonometry. I am trying to deduce a destination latitude and longitude from a start lat and log and distance and bearing.
Fortunately, I found an amazing site which describes exactly the function I need:
http://www.movable-type.co.uk/scripts/latlong.html "
Destination point given distance and bearing from start point "
My ultimate aim is to have this calculation done on an Arduino, but I'm prototyping it in processing... Here is what I have so far.
- void setup()
- {
- float CurLon = 0;
- float CurLat = 50;
-
- int Eradius = 6371; // mean radius of the earth
- float Bearing = 90; // Bearing of travel
- float Distance = 1; // km per update
- float rBearing = radians(Bearing); // convert Bearing to Radians
- float aDistance = Distance/Eradius; // convert dist to angular distance in radians
- float DestLat = asin(sin(CurLat)*cos(aDistance)+cos(CurLat)*sin(aDistance)*cos(rBearing));
- float DestLon = CurLon + atan2(sin(rBearing)*sin(aDistance)*cos(CurLat),cos(aDistance)-sin(CurLat)*sin(DestLat));
- DestLon = (DestLon+3*PI)%(2*PI) - PI; // normalise to -180..+180º
-
- System.out.printf("starting at a Longitude of %f and a Latitude of %f\n",CurLon,CurLat);
- System.out.printf("if we travel %f km on a bearing of %f degrees (%f angular distance and %f in radians)\n",Distance,Bearing,aDistance,rBearing);
- System.out.printf("we end up at Longitude of %f and a Latitude of %f\n",DestLon,DestLat);
- }
The output reads:
starting at a Longitude of 0.000000 and a Latitude of 50.000000 if we travel 1.000000 km on a bearing of 90.000000 degrees (0.000157 angular distance and 1.570796 in radians) we end up at Longitude of 0.000163 and a Latitude of -0.265482
I have obviously got something wrong somewhere, but I don't understand trig deeply enough, or equations of the Great Circle / Haversine to debug what is going wrong here. Does anyone have any experience with this kind of calculation?
thanks
Jim
1