/Proj4/PJ_lcca.c

http://github.com/route-me/route-me · C · 76 lines · 64 code · 6 blank · 6 comment · 9 complexity · 343d16310027e7fdf17c1c91c36adeb3 MD5 · raw file

  1. static const char RCS_ID[] = "$Id: PJ_lcca.c,v 1.1 2003/03/04 02:59:41 warmerda Exp $";
  2. /* PROJ.4 Cartographic Projection System -- Revision Log:
  3. **$Log: PJ_lcca.c,v $
  4. **Revision 1.1 2003/03/04 02:59:41 warmerda
  5. **New
  6. **
  7. */
  8. #define MAX_ITER 10
  9. #define DEL_TOL 1e-12
  10. #define PROJ_PARMS__ \
  11. double *en; \
  12. double r0, l, M0; \
  13. double C;
  14. #define PJ_LIB__
  15. #include "projects.h"
  16. PROJ_HEAD(lcca, "Lambert Conformal Conic Alternative")
  17. "\n\tConic, Sph&Ell\n\tlat_0=";
  18. static double /* func to compute dr */
  19. fS(double S, double C) {
  20. return(S * ( 1. + S * S * C));
  21. }
  22. static double /* deriv of fs */
  23. fSp(double S, double C) {
  24. return(1. + 3.* S * S * C);
  25. }
  26. FORWARD(e_forward); /* ellipsoid */
  27. double S, S3, r, dr;
  28. S = pj_mlfn(lp.phi, sin(lp.phi), cos(lp.phi), P->en) - P->M0;
  29. dr = fS(S, P->C);
  30. r = P->r0 - dr;
  31. xy.x = P->k0 * (r * sin( lp.lam *= P->l ) );
  32. xy.y = P->k0 * (P->r0 - r * cos(lp.lam) );
  33. return (xy);
  34. }
  35. INVERSE(e_inverse); /* ellipsoid & spheroid */
  36. double theta, dr, S, dif;
  37. int i;
  38. xy.x /= P->k0;
  39. xy.y /= P->k0;
  40. theta = atan2(xy.x , P->r0 - xy.y);
  41. dr = xy.y - xy.x * tan(0.5 * theta);
  42. lp.lam = theta / P->l;
  43. S = dr;
  44. for (i = MAX_ITER; i ; --i) {
  45. S -= (dif = (fS(S, P->C) - dr) / fSp(S, P->C));
  46. if (fabs(dif) < DEL_TOL) break;
  47. }
  48. if (!i) I_ERROR
  49. lp.phi = pj_inv_mlfn(S + P->M0, P->es, P->en);
  50. return (lp);
  51. }
  52. FREEUP; if (P) { if (P->en) pj_dalloc(P->en); pj_dalloc(P); } }
  53. ENTRY0(lcca)
  54. double s2p0, N0, R0, tan0, tan20;
  55. if (!(P->en = pj_enfn(P->es))) E_ERROR_0;
  56. if (!pj_param(P->params, "tlat_0").i) E_ERROR(50);
  57. if (P->phi0 == 0.) E_ERROR(51);
  58. P->l = sin(P->phi0);
  59. P->M0 = pj_mlfn(P->phi0, P->l, cos(P->phi0), P->en);
  60. s2p0 = P->l * P->l;
  61. R0 = 1. / (1. - P->es * s2p0);
  62. N0 = sqrt(R0);
  63. R0 *= P->one_es * N0;
  64. tan0 = tan(P->phi0);
  65. tan20 = tan0 * tan0;
  66. P->r0 = N0 / tan0;
  67. P->C = 1. / (6. * R0 * N0);
  68. P->inv = e_inverse;
  69. P->fwd = e_forward;
  70. ENDENTRY(P)