从这个链接:
这是 C 中的一个实现。
#define PI 3.14159265358979323846
double degrees_radians(double d) { return d * PI / 180.0; }
double radians_degrees(double r) { return r * 180.0 / PI; }
double latitude(double lat1, double lon1, double lat2, double lon2, double lon)
{
return atan((sin(lat1)*cos(lat2)*sin(lon-lon2)-sin(lat2)*cos(lat1)*sin(lon-lon1))/(cos(lat1)*cos(lat2)*sin(lon1-lon2)));
}
int main()
{
// start and end in degrees
double lat1_d = 52.517;
double lon1_d = 13.40;
double lat2_d = 35.70;
double lon2_d = 139.767;
// start and end in radians
double lat1_r = degrees_radians(lat1_d);
double lon1_r = degrees_radians(lon1_d);
double lat2_r = degrees_radians(lat2_d);
double lon2_r = degrees_radians(lon2_d);
// interpolate latitide at every degree of longitude between 1 and 2
for (double lon = ceil(lon1_d); lon < lon2_d; lon += 1.0)
{
double lat_r = latitude(lat1_r, lon1_r, lat2_r, lon2_r, degrees_radians(lon));
double lat_d = radians_degrees(lat_r);
printf("%.3f , %.3f\n", lat_d, lon);
}
return 0;
}
在柏林和东京之间的大圆上达到的最大纬度显示为经度 68° 处的 66.183°。