/Proj4/PJ_eqdc.c

http://github.com/route-me/route-me · C · 88 lines · 85 code · 3 blank · 0 comment · 13 complexity · bd8122eb944b6dd05bb9583a0fa45a1f MD5 · raw file

  1. #ifndef lint
  2. static const char SCCSID[]="@(#)PJ_eqdc.c 4.2 94/03/16 GIE REL";
  3. #endif
  4. #define PROJ_PARMS__ \
  5. double phi1; \
  6. double phi2; \
  7. double n; \
  8. double rho; \
  9. double rho0; \
  10. double c; \
  11. double *en; \
  12. int ellips;
  13. #define PJ_LIB__
  14. #include "projects.h"
  15. PROJ_HEAD(eqdc, "Equidistant Conic")
  16. "\n\tConic, Sph&Ell\n\tlat_1= lat_2=";
  17. # define EPS10 1.e-10
  18. FORWARD(e_forward); /* sphere & ellipsoid */
  19. P->rho = P->c - (P->ellips ? pj_mlfn(lp.phi, sin(lp.phi),
  20. cos(lp.phi), P->en) : lp.phi);
  21. xy.x = P->rho * sin( lp.lam *= P->n );
  22. xy.y = P->rho0 - P->rho * cos(lp.lam);
  23. return (xy);
  24. }
  25. INVERSE(e_inverse); /* sphere & ellipsoid */
  26. if ((P->rho = hypot(xy.x, xy.y = P->rho0 - xy.y)) != 0.0 ) {
  27. if (P->n < 0.) {
  28. P->rho = -P->rho;
  29. xy.x = -xy.x;
  30. xy.y = -xy.y;
  31. }
  32. lp.phi = P->c - P->rho;
  33. if (P->ellips)
  34. lp.phi = pj_inv_mlfn(lp.phi, P->es, P->en);
  35. lp.lam = atan2(xy.x, xy.y) / P->n;
  36. } else {
  37. lp.lam = 0.;
  38. lp.phi = P->n > 0. ? HALFPI : - HALFPI;
  39. }
  40. return (lp);
  41. }
  42. SPECIAL(fac) {
  43. double sinphi, cosphi;
  44. sinphi = sin(lp.phi);
  45. cosphi = cos(lp.phi);
  46. fac->code |= IS_ANAL_HK;
  47. fac->h = 1.;
  48. fac->k = P->n * (P->c - (P->ellips ? pj_mlfn(lp.phi, sinphi,
  49. cosphi, P->en) : lp.phi)) / pj_msfn(sinphi, cosphi, P->es);
  50. }
  51. FREEUP; if (P) { if (P->en) pj_dalloc(P->en); pj_dalloc(P); } }
  52. ENTRY1(eqdc, en)
  53. double cosphi, sinphi;
  54. int secant;
  55. P->phi1 = pj_param(P->params, "rlat_1").f;
  56. P->phi2 = pj_param(P->params, "rlat_2").f;
  57. if (fabs(P->phi1 + P->phi2) < EPS10) E_ERROR(-21);
  58. if (!(P->en = pj_enfn(P->es)))
  59. E_ERROR_0;
  60. P->n = sinphi = sin(P->phi1);
  61. cosphi = cos(P->phi1);
  62. secant = fabs(P->phi1 - P->phi2) >= EPS10;
  63. if( (P->ellips = (P->es > 0.)) ) {
  64. double ml1, m1;
  65. m1 = pj_msfn(sinphi, cosphi, P->es);
  66. ml1 = pj_mlfn(P->phi1, sinphi, cosphi, P->en);
  67. if (secant) { /* secant cone */
  68. sinphi = sin(P->phi2);
  69. cosphi = cos(P->phi2);
  70. P->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) /
  71. (pj_mlfn(P->phi2, sinphi, cosphi, P->en) - ml1);
  72. }
  73. P->c = ml1 + m1 / P->n;
  74. P->rho0 = P->c - pj_mlfn(P->phi0, sin(P->phi0),
  75. cos(P->phi0), P->en);
  76. } else {
  77. if (secant)
  78. P->n = (cosphi - cos(P->phi2)) / (P->phi2 - P->phi1);
  79. P->c = P->phi1 + cos(P->phi1) / P->n;
  80. P->rho0 = P->c - P->phi0;
  81. }
  82. P->inv = e_inverse;
  83. P->fwd = e_forward;
  84. P->spc = fac;
  85. ENDENTRY(P)