PageRenderTime 37ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Proj4/PJ_tpeqd.c

http://github.com/route-me/route-me
C | 79 lines | 74 code | 3 blank | 2 comment | 7 complexity | aa81ed3445de429e01f6f85cf7a5f4f7 MD5 | raw file
  1. #ifndef lint
  2. static const char SCCSID[]="@(#)PJ_tpeqd.c 4.1 94/02/15 GIE REL";
  3. #endif
  4. #define PROJ_PARMS__ \
  5. double cp1, sp1, cp2, sp2, ccs, cs, sc, r2z0, z02, dlam2; \
  6. double hz0, thz0, rhshz0, ca, sa, lp, lamc;
  7. #define PJ_LIB__
  8. #include "projects.h"
  9. PROJ_HEAD(tpeqd, "Two Point Equidistant")
  10. "\n\tMisc Sph\n\tlat_1= lon_1= lat_2= lon_2=";
  11. FORWARD(s_forward); /* sphere */
  12. double t, z1, z2, dl1, dl2, sp, cp;
  13. sp = sin(lp.phi);
  14. cp = cos(lp.phi);
  15. z1 = aacos(P->sp1 * sp + P->cp1 * cp * cos(dl1 = lp.lam + P->dlam2));
  16. z2 = aacos(P->sp2 * sp + P->cp2 * cp * cos(dl2 = lp.lam - P->dlam2));
  17. z1 *= z1;
  18. z2 *= z2;
  19. xy.x = P->r2z0 * (t = z1 - z2);
  20. t = P->z02 - t;
  21. xy.y = P->r2z0 * asqrt(4. * P->z02 * z2 - t * t);
  22. if ((P->ccs * sp - cp * (P->cs * sin(dl1) - P->sc * sin(dl2))) < 0.)
  23. xy.y = -xy.y;
  24. return xy;
  25. }
  26. INVERSE(s_inverse); /* sphere */
  27. double cz1, cz2, s, d, cp, sp;
  28. cz1 = cos(hypot(xy.y, xy.x + P->hz0));
  29. cz2 = cos(hypot(xy.y, xy.x - P->hz0));
  30. s = cz1 + cz2;
  31. d = cz1 - cz2;
  32. lp.lam = - atan2(d, (s * P->thz0));
  33. lp.phi = aacos(hypot(P->thz0 * s, d) * P->rhshz0);
  34. if ( xy.y < 0. )
  35. lp.phi = - lp.phi;
  36. /* lam--phi now in system relative to P1--P2 base equator */
  37. sp = sin(lp.phi);
  38. cp = cos(lp.phi);
  39. lp.phi = aasin(P->sa * sp + P->ca * cp * (s = cos(lp.lam -= P->lp)));
  40. lp.lam = atan2(cp * sin(lp.lam), P->sa * cp * s - P->ca * sp) + P->lamc;
  41. return lp;
  42. }
  43. FREEUP; if (P) pj_dalloc(P); }
  44. ENTRY0(tpeqd)
  45. double lam_1, lam_2, phi_1, phi_2, A12, pp;
  46. /* get control point locations */
  47. phi_1 = pj_param(P->params, "rlat_1").f;
  48. lam_1 = pj_param(P->params, "rlon_1").f;
  49. phi_2 = pj_param(P->params, "rlat_2").f;
  50. lam_2 = pj_param(P->params, "rlon_2").f;
  51. if (phi_1 == phi_2 && lam_1 == lam_2) E_ERROR(-25);
  52. P->lam0 = adjlon(0.5 * (lam_1 + lam_2));
  53. P->dlam2 = adjlon(lam_2 - lam_1);
  54. P->cp1 = cos(phi_1);
  55. P->cp2 = cos(phi_2);
  56. P->sp1 = sin(phi_1);
  57. P->sp2 = sin(phi_2);
  58. P->cs = P->cp1 * P->sp2;
  59. P->sc = P->sp1 * P->cp2;
  60. P->ccs = P->cp1 * P->cp2 * sin(P->dlam2);
  61. P->z02 = aacos(P->sp1 * P->sp2 + P->cp1 * P->cp2 * cos(P->dlam2));
  62. P->hz0 = .5 * P->z02;
  63. A12 = atan2(P->cp2 * sin(P->dlam2),
  64. P->cp1 * P->sp2 - P->sp1 * P->cp2 * cos(P->dlam2));
  65. P->ca = cos(pp = aasin(P->cp1 * sin(A12)));
  66. P->sa = sin(pp);
  67. P->lp = adjlon(atan2(P->cp1 * cos(A12), P->sp1) - P->hz0);
  68. P->dlam2 *= .5;
  69. P->lamc = HALFPI - atan2(sin(A12) * P->sp1, cos(A12)) - P->dlam2;
  70. P->thz0 = tan(P->hz0);
  71. P->rhshz0 = .5 / sin(P->hz0);
  72. P->r2z0 = 0.5 / P->z02;
  73. P->z02 *= P->z02;
  74. P->inv = s_inverse; P->fwd = s_forward;
  75. P->es = 0.;
  76. ENDENTRY(P)