/Proj4/geod_inv.c

http://github.com/route-me/route-me · C · 59 lines · 58 code · 1 blank · 0 comment · 6 complexity · 61e5e07b2affee7b11b7124bf8808cd1 MD5 · raw file

  1. #ifndef lint
  2. static const char SCCSID[]="@(#)geod_inv.c 4.5 95/09/23 GIE REL";
  3. #endif
  4. # include "projects.h"
  5. # include "geodesic.h"
  6. # define DTOL 1e-12
  7. void
  8. geod_inv(void) {
  9. double th1,th2,thm,dthm,dlamm,dlam,sindlamm,costhm,sinthm,cosdthm,
  10. sindthm,L,E,cosd,d,X,Y,T,sind,tandlammp,u,v,D,A,B;
  11. if (ellipse) {
  12. th1 = atan(onef * tan(phi1));
  13. th2 = atan(onef * tan(phi2));
  14. } else {
  15. th1 = phi1;
  16. th2 = phi2;
  17. }
  18. thm = .5 * (th1 + th2);
  19. dthm = .5 * (th2 - th1);
  20. dlamm = .5 * ( dlam = adjlon(lam2 - lam1) );
  21. if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
  22. al12 = al21 = geod_S = 0.;
  23. return;
  24. }
  25. sindlamm = sin(dlamm);
  26. costhm = cos(thm); sinthm = sin(thm);
  27. cosdthm = cos(dthm); sindthm = sin(dthm);
  28. L = sindthm * sindthm + (cosdthm * cosdthm - sinthm * sinthm)
  29. * sindlamm * sindlamm;
  30. d = acos(cosd = 1 - L - L);
  31. if (ellipse) {
  32. E = cosd + cosd;
  33. sind = sin( d );
  34. Y = sinthm * cosdthm;
  35. Y *= (Y + Y) / (1. - L);
  36. T = sindthm * costhm;
  37. T *= (T + T) / L;
  38. X = Y + T;
  39. Y -= T;
  40. T = d / sind;
  41. D = 4. * T * T;
  42. A = D * E;
  43. B = D + D;
  44. geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
  45. f64 * (X * (A + (T - .5 * (A - E)) * X) -
  46. Y * (B + E * Y) + D * X * Y));
  47. tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
  48. (f2 * T + f64 * (32. * T - (20. * T - A)
  49. * X - (B + 4.) * Y)) * tan(dlam)));
  50. } else {
  51. geod_S = geod_a * d;
  52. tandlammp = tan(dlamm);
  53. }
  54. u = atan2(sindthm , (tandlammp * costhm));
  55. v = atan2(cosdthm , (tandlammp * sinthm));
  56. al12 = adjlon(TWOPI + v - u);
  57. al21 = adjlon(TWOPI - v - u);
  58. }