/Proj4/PJ_hatano.c

http://github.com/route-me/route-me · C · 53 lines · 51 code · 2 blank · 0 comment · 7 complexity · 81c232be867fa58ca05ed206d20a905d MD5 · raw file

  1. #ifndef lint
  2. static const char SCCSID[]="@(#)PJ_hatano.c 4.1 94/02/15 GIE REL";
  3. #endif
  4. #define PJ_LIB__
  5. #include "projects.h"
  6. PROJ_HEAD(hatano, "Hatano Asymmetrical Equal Area") "\n\tPCyl, Sph.";
  7. #define NITER 20
  8. #define EPS 1e-7
  9. #define ONETOL 1.000001
  10. #define CN 2.67595
  11. #define CS 2.43763
  12. #define RCN 0.37369906014686373063
  13. #define RCS 0.41023453108141924738
  14. #define FYCN 1.75859
  15. #define FYCS 1.93052
  16. #define RYCN 0.56863737426006061674
  17. #define RYCS 0.51799515156538134803
  18. #define FXC 0.85
  19. #define RXC 1.17647058823529411764
  20. FORWARD(s_forward); /* spheroid */
  21. double th1, c;
  22. int i;
  23. c = sin(lp.phi) * (lp.phi < 0. ? CS : CN);
  24. for (i = NITER; i; --i) {
  25. lp.phi -= th1 = (lp.phi + sin(lp.phi) - c) / (1. + cos(lp.phi));
  26. if (fabs(th1) < EPS) break;
  27. }
  28. xy.x = FXC * lp.lam * cos(lp.phi *= .5);
  29. xy.y = sin(lp.phi) * (lp.phi < 0. ? FYCS : FYCN);
  30. return (xy);
  31. }
  32. INVERSE(s_inverse); /* spheroid */
  33. double th;
  34. th = xy.y * ( xy.y < 0. ? RYCS : RYCN);
  35. if (fabs(th) > 1.)
  36. if (fabs(th) > ONETOL) I_ERROR
  37. else th = th > 0. ? HALFPI : - HALFPI;
  38. else
  39. th = asin(th);
  40. lp.lam = RXC * xy.x / cos(th);
  41. th += th;
  42. lp.phi = (th + sin(th)) * (xy.y < 0. ? RCS : RCN);
  43. if (fabs(lp.phi) > 1.)
  44. if (fabs(lp.phi) > ONETOL) I_ERROR
  45. else lp.phi = lp.phi > 0. ? HALFPI : - HALFPI;
  46. else
  47. lp.phi = asin(lp.phi);
  48. return (lp);
  49. }
  50. FREEUP; if (P) pj_dalloc(P); }
  51. ENTRY0(hatano) P->es = 0.; P->inv = s_inverse; P->fwd = s_forward; ENDENTRY(P)