/*
 * Takes degrees lat/long pairs,
 * returns miles + compass degrees
 * Bart Massey 2000
 * From Javascript by Jeff Waldock 1997
 * http://jeff.sci.shu.ac.uk/jw/javascript/js2.html
 */

real[] function great_circle
  (real start_lat, real start_lon, real end_lat, real end_lon) {
	real rad = pi / 180;
	/* real earth_radius = 6371.2 km ; */
	real earth_radius = 3958.9; /* miles */
	real a = (90 - start_lat) * rad;
	real b = (90 - end_lat) * rad;
	real phi = (end_lon - start_lon) * rad;
	real cosr = cos(a) * cos(b) + sin(a) * sin(b) * cos(phi);
	real r = acos(cosr);
	real rdist = earth_radius * r;
	real sinth = sin(phi) * sin(b) / sin(r);
	real th = asin(sinth) / rad;
	return [*]{rdist, th};
}
