PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Proj4/PJ_mod_ster.c

http://github.com/route-me/route-me
C | 214 lines | 204 code | 9 blank | 1 comment | 13 complexity | 0691829146fffd6d10b33c1bc645a0d9 MD5 | raw file
  1. #ifndef lint
  2. static const char SCCSID[]="@(#)PJ_mod_ster.c 4.1 94/02/15 GIE REL";
  3. #endif
  4. /* based upon Snyder and Linck, USGS-NMD */
  5. #define PROJ_PARMS__ \
  6. COMPLEX *zcoeff; \
  7. double cchio, schio; \
  8. int n;
  9. #define PJ_LIB__
  10. #include "projects.h"
  11. PROJ_HEAD(mil_os, "Miller Oblated Stereographic") "\n\tAzi(mod)";
  12. PROJ_HEAD(lee_os, "Lee Oblated Stereographic") "\n\tAzi(mod)";
  13. PROJ_HEAD(gs48, "Mod. Stererographics of 48 U.S.") "\n\tAzi(mod)";
  14. PROJ_HEAD(alsk, "Mod. Stererographics of Alaska") "\n\tAzi(mod)";
  15. PROJ_HEAD(gs50, "Mod. Stererographics of 50 U.S.") "\n\tAzi(mod)";
  16. #define EPSLN 1e-10
  17. FORWARD(e_forward); /* ellipsoid */
  18. double sinlon, coslon, esphi, chi, schi, cchi, s;
  19. COMPLEX p;
  20. sinlon = sin(lp.lam);
  21. coslon = cos(lp.lam);
  22. esphi = P->e * sin(lp.phi);
  23. chi = 2. * atan(tan((HALFPI + lp.phi) * .5) *
  24. pow((1. - esphi) / (1. + esphi), P->e * .5)) - HALFPI;
  25. schi = sin(chi);
  26. cchi = cos(chi);
  27. s = 2. / (1. + P->schio * schi + P->cchio * cchi * coslon);
  28. p.r = s * cchi * sinlon;
  29. p.i = s * (P->cchio * schi - P->schio * cchi * coslon);
  30. p = pj_zpoly1(p, P->zcoeff, P->n);
  31. xy.x = p.r;
  32. xy.y = p.i;
  33. return xy;
  34. }
  35. INVERSE(e_inverse); /* ellipsoid */
  36. int nn;
  37. COMPLEX p, fxy, fpxy, dp;
  38. double den, rh, z, sinz, cosz, chi, phi, dphi, esphi;
  39. p.r = xy.x;
  40. p.i = xy.y;
  41. for (nn = 20; nn ;--nn) {
  42. fxy = pj_zpolyd1(p, P->zcoeff, P->n, &fpxy);
  43. fxy.r -= xy.x;
  44. fxy.i -= xy.y;
  45. den = fpxy.r * fpxy.r + fpxy.i * fpxy.i;
  46. dp.r = -(fxy.r * fpxy.r + fxy.i * fpxy.i) / den;
  47. dp.i = -(fxy.i * fpxy.r - fxy.r * fpxy.i) / den;
  48. p.r += dp.r;
  49. p.i += dp.i;
  50. if ((fabs(dp.r) + fabs(dp.i)) <= EPSLN)
  51. break;
  52. }
  53. if (nn) {
  54. rh = hypot(p.r, p.i);
  55. z = 2. * atan(.5 * rh);
  56. sinz = sin(z);
  57. cosz = cos(z);
  58. lp.lam = P->lam0;
  59. if (fabs(rh) <= EPSLN) {
  60. lp.phi = P->phi0;
  61. return lp;
  62. }
  63. chi = aasin(cosz * P->schio + p.i * sinz * P->cchio / rh);
  64. phi = chi;
  65. for (nn = 20; nn ;--nn) {
  66. esphi = P->e * sin(phi);
  67. dphi = 2. * atan(tan((HALFPI + chi) * .5) *
  68. pow((1. + esphi) / (1. - esphi), P->e * .5)) - HALFPI - phi;
  69. phi += dphi;
  70. if (fabs(dphi) <= EPSLN)
  71. break;
  72. }
  73. }
  74. if (nn) {
  75. lp.phi = phi;
  76. lp.lam = atan2(p.r * sinz, rh * P->cchio * cosz - p.i *
  77. P->schio * sinz);
  78. } else
  79. lp.lam = lp.phi = HUGE_VAL;
  80. return lp;
  81. }
  82. FREEUP; if (P) pj_dalloc(P); }
  83. static PJ *
  84. setup(PJ *P) { /* general initialization */
  85. double esphi, chio;
  86. if (P->es) {
  87. esphi = P->e * sin(P->phi0);
  88. chio = 2. * atan(tan((HALFPI + P->phi0) * .5) *
  89. pow((1. - esphi) / (1. + esphi), P->e * .5)) - HALFPI;
  90. } else
  91. chio = P->phi0;
  92. P->schio = sin(chio);
  93. P->cchio = cos(chio);
  94. P->inv = e_inverse; P->fwd = e_forward;
  95. return P;
  96. }
  97. ENTRY0(mil_os)
  98. static COMPLEX /* Miller Oblated Stereographic */
  99. AB[] = {
  100. {0.924500, 0.},
  101. {0., 0.},
  102. {0.019430, 0.}
  103. };
  104. P->n = 2;
  105. P->lam0 = DEG_TO_RAD * 20.;
  106. P->phi0 = DEG_TO_RAD * 18.;
  107. P->zcoeff = AB;
  108. P->es = 0.;
  109. ENDENTRY(setup(P))
  110. ENTRY0(lee_os)
  111. static COMPLEX /* Lee Oblated Stereographic */
  112. AB[] = {
  113. {0.721316, 0.},
  114. {0., 0.},
  115. {-0.0088162, -0.00617325}
  116. };
  117. P->n = 2;
  118. P->lam0 = DEG_TO_RAD * -165.;
  119. P->phi0 = DEG_TO_RAD * -10.;
  120. P->zcoeff = AB;
  121. P->es = 0.;
  122. ENDENTRY(setup(P))
  123. ENTRY0(gs48)
  124. static COMPLEX /* 48 United States */
  125. AB[] = {
  126. {0.98879, 0.},
  127. {0., 0.},
  128. {-0.050909, 0.},
  129. {0., 0.},
  130. {0.075528, 0.}
  131. };
  132. P->n = 4;
  133. P->lam0 = DEG_TO_RAD * -96.;
  134. P->phi0 = DEG_TO_RAD * -39.;
  135. P->zcoeff = AB;
  136. P->es = 0.;
  137. P->a = 6370997.;
  138. ENDENTRY(setup(P))
  139. ENTRY0(alsk)
  140. static COMPLEX
  141. ABe[] = { /* Alaska ellipsoid */
  142. {.9945303, 0.},
  143. {.0052083, -.0027404},
  144. {.0072721, .0048181},
  145. {-.0151089, -.1932526},
  146. {.0642675, -.1381226},
  147. {.3582802, -.2884586}},
  148. ABs[] = { /* Alaska sphere */
  149. {.9972523, 0.},
  150. {.0052513, -.0041175},
  151. {.0074606, .0048125},
  152. {-.0153783, -.1968253},
  153. {.0636871, -.1408027},
  154. {.3660976, -.2937382}
  155. };
  156. P->n = 5;
  157. P->lam0 = DEG_TO_RAD * -152.;
  158. P->phi0 = DEG_TO_RAD * 64.;
  159. if (P->es) { /* fixed ellipsoid/sphere */
  160. P->zcoeff = ABe;
  161. P->a = 6378206.4;
  162. P->e = sqrt(P->es = 0.00676866);
  163. } else {
  164. P->zcoeff = ABs;
  165. P->a = 6370997.;
  166. }
  167. ENDENTRY(setup(P))
  168. ENTRY0(gs50)
  169. static COMPLEX
  170. ABe[] = { /* GS50 ellipsoid */
  171. {.9827497, 0.},
  172. {.0210669, .0053804},
  173. {-.1031415, -.0571664},
  174. {-.0323337, -.0322847},
  175. {.0502303, .1211983},
  176. {.0251805, .0895678},
  177. {-.0012315, -.1416121},
  178. {.0072202, -.1317091},
  179. {-.0194029, .0759677},
  180. {-.0210072, .0834037}
  181. },
  182. ABs[] = { /* GS50 sphere */
  183. {.9842990, 0.},
  184. {.0211642, .0037608},
  185. {-.1036018, -.0575102},
  186. {-.0329095, -.0320119},
  187. {.0499471, .1223335},
  188. {.0260460, .0899805},
  189. {.0007388, -.1435792},
  190. {.0075848, -.1334108},
  191. {-.0216473, .0776645},
  192. {-.0225161, .0853673}
  193. };
  194. P->n = 9;
  195. P->lam0 = DEG_TO_RAD * -120.;
  196. P->phi0 = DEG_TO_RAD * 45.;
  197. if (P->es) { /* fixed ellipsoid/sphere */
  198. P->zcoeff = ABe;
  199. P->a = 6378206.4;
  200. P->e = sqrt(P->es = 0.00676866);
  201. } else {
  202. P->zcoeff = ABs;
  203. P->a = 6370997.;
  204. }
  205. ENDENTRY(setup(P))