Computes the direction of the geodesic joining two points on the spheroid.
290 double lambda =
s->lon -
r->lon;
291 double omf = 1 - spheroid->
f;
292 double u1 = atan(omf * tan(
r->lat));
293 double cos_u1 = cos(u1);
294 double sin_u1 = sin(u1);
295 double u2 = atan(omf * tan(
s->lat));
296 double cos_u2 = cos(u2);
297 double sin_u2 = sin(u2);
299 double omega = lambda;
300 double alpha, sigma, sin_sigma, cos_sigma, cos2_sigma_m, sqr_sin_sigma, last_lambda;
301 double sin_alpha, cos_alphasq, C, alphaFD;
304 sqr_sin_sigma =
POW2(cos_u2 * sin(lambda)) +
305 POW2((cos_u1 * sin_u2 - sin_u1 * cos_u2 * cos(lambda)));
306 sin_sigma = sqrt(sqr_sin_sigma);
307 cos_sigma = sin_u1 * sin_u2 + cos_u1 * cos_u2 * cos(lambda);
308 sigma = atan2(sin_sigma, cos_sigma);
309 sin_alpha = cos_u1 * cos_u2 * sin(lambda) / sin(sigma);
312 if ( sin_alpha > 1.0 )
314 else if ( sin_alpha < -1.0 )
315 alpha = -1.0 * M_PI_2;
317 alpha = asin(sin_alpha);
319 cos_alphasq =
POW2(cos(alpha));
320 cos2_sigma_m = cos(sigma) - (2.0 * sin_u1 * sin_u2 / cos_alphasq);
323 if ( cos2_sigma_m > 1.0 )
325 if ( cos2_sigma_m < -1.0 )
328 C = (spheroid->
f / 16.0) * cos_alphasq * (4.0 + spheroid->
f * (4.0 - 3.0 * cos_alphasq));
329 last_lambda = lambda;
330 lambda = omega + (1.0 - C) * spheroid->
f * sin(alpha) * (sigma + C * sin(sigma) *
331 (cos2_sigma_m + C * cos(sigma) * (-1.0 + 2.0 *
POW2(cos2_sigma_m))));
334 while ( (i < 999) && (lambda != 0) && (fabs((last_lambda - lambda) / lambda) > 1.0e-9) );
336 alphaFD = atan2((cos_u2 * sin(lambda)),
337 (cos_u1 * sin_u2 - sin_u1 * cos_u2 * cos(lambda)));
340 alphaFD = alphaFD + 2.0 * M_PI;
342 if (alphaFD > 2.0 * M_PI)
344 alphaFD = alphaFD - 2.0 * M_PI;