On 10 Aug 2006, at 18:54, Just van den Broecke wrote:
For the experts: I am looking for a formula, preferably as Java
(Script)-code, to calculate the course between two lon/lat pairs as
a value between 0 (north), through 180 (south) to 360 degrees (like
in the values from a GPS RMC sample). I can calculate Great Circle
distance, but somehow couldn't find course-calculations Googling.
From the gpsbabel sources:
/* This value is the heading you'd leave point 1 at to arrive at
point 2.
* Inputs and outputs are in radians.
*/
double heading( double lat1, double lon1, double lat2, double lon2 ) {
double v1, v2;
v1 = sin(lon1 - lon2) * cos(lat2);
v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 -
lon2);
/* rounding error protection */
if (fabs(v1) < 1e-15) v1 = 0.0;
if (fabs(v2) < 1e-15) v2 = 0.0;
return atan2(v1, v2);
}
It's C but it's not going to be hard to translate into JavaScript :)
--
Andy Armstrong, hexten.net
_______________________________________________
Geowanking mailing list
[email protected]
http://lists.burri.to/mailman/listinfo/geowanking