- double a = (90 - start_lat) * rad;
- double b = (90 - end_lat) * rad;
- double phi = (end_lon - start_lon) * rad;
- double cosr = cos(a) * cos(b) + sin(a) * sin(b) * cos(phi);
- double r = acos(cosr);
- double rdist = earth_radius * r;
- double sinth = sin(phi) * sin(b) / sin(r);
- double th = asin(sinth) / rad;
- *dist = rdist;
- *bearing = th;
+ double lat1 = rad * start_lat;
+ double lon1 = -rad * start_lon;
+ double lat2 = rad * end_lat;
+ double lon2 = -rad * end_lon;
+
+ double d = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
+ double argacos = (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1));
+ double crs;
+ if (sin(lon2-lon1) < 0)
+ crs = acos(argacos);
+ else
+ crs = 2 * M_PI - acos(argacos);
+ *dist = d * earth_radius;
+ *bearing = crs * 180/M_PI;
+}
+
+static void
+aoview_state_add_deg(char *label, double deg)
+{
+ double int_part;
+ double min;
+
+ int_part = floor (deg);
+ min = (deg - int_part) * 60.0;
+ aoview_table_add_row(label, "%d°%lf'",
+ (int) int_part, min);
+