/Proj4/PJ_sterea.c

http://github.com/route-me/route-me · C · 97 lines · 51 code · 6 blank · 40 comment · 5 complexity · a1d29f28fd0752e6a2f7aaf845ae07ac MD5 · raw file

  1. /*
  2. ** libproj -- library of cartographic projections
  3. **
  4. ** Copyright (c) 2003 Gerald I. Evenden
  5. */
  6. static const char
  7. LIBPROJ_ID[] = "$Id: PJ_sterea.c,v 1.1 2004/10/20 17:04:00 fwarmerdam Exp $";
  8. /*
  9. ** Permission is hereby granted, free of charge, to any person obtaining
  10. ** a copy of this software and associated documentation files (the
  11. ** "Software"), to deal in the Software without restriction, including
  12. ** without limitation the rights to use, copy, modify, merge, publish,
  13. ** distribute, sublicense, and/or sell copies of the Software, and to
  14. ** permit persons to whom the Software is furnished to do so, subject to
  15. ** the following conditions:
  16. **
  17. ** The above copyright notice and this permission notice shall be
  18. ** included in all copies or substantial portions of the Software.
  19. **
  20. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23. ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24. ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. #define PROJ_PARMS__ \
  29. double phic0; \
  30. double cosc0, sinc0; \
  31. double R2; \
  32. void *en;
  33. #define PJ_LIB__
  34. #include "projects.h"
  35. PROJ_HEAD(sterea, "Oblique Stereographic Alternative")
  36. "\n\tAzimuthal, Sph&Ell";
  37. # define DEL_TOL 1.e-14
  38. # define MAX_ITER 10
  39. FORWARD(e_forward); /* ellipsoid */
  40. double cosc, sinc, cosl, k;
  41. lp = pj_gauss(lp, P->en);
  42. sinc = sin(lp.phi);
  43. cosc = cos(lp.phi);
  44. cosl = cos(lp.lam);
  45. k = P->k0 * P->R2 / (1. + P->sinc0 * sinc + P->cosc0 * cosc * cosl);
  46. xy.x = k * cosc * sin(lp.lam);
  47. xy.y = k * (P->cosc0 * sinc - P->sinc0 * cosc * cosl);
  48. return (xy);
  49. }
  50. INVERSE(e_inverse); /* ellipsoid */
  51. double rho, c, sinc, cosc;
  52. xy.x /= P->k0;
  53. xy.y /= P->k0;
  54. if((rho = hypot(xy.x, xy.y))) {
  55. c = 2. * atan2(rho, P->R2);
  56. sinc = sin(c);
  57. cosc = cos(c);
  58. lp.phi = asin(cosc * P->sinc0 + xy.y * sinc * P->cosc0 / rho);
  59. lp.lam = atan2(xy.x * sinc, rho * P->cosc0 * cosc -
  60. xy.y * P->sinc0 * sinc);
  61. } else {
  62. lp.phi = P->phic0;
  63. lp.lam = 0.;
  64. }
  65. return(pj_inv_gauss(lp, P->en));
  66. }
  67. FREEUP; if (P) { if (P->en) free(P->en); free(P); } }
  68. ENTRY0(sterea)
  69. double R;
  70. if (!(P->en = pj_gauss_ini(P->e, P->phi0, &(P->phic0), &R))) E_ERROR_0;
  71. P->sinc0 = sin(P->phic0);
  72. P->cosc0 = cos(P->phic0);
  73. P->R2 = 2. * R;
  74. P->inv = e_inverse;
  75. P->fwd = e_forward;
  76. ENDENTRY(P)
  77. /*
  78. ** $Log: PJ_sterea.c,v $
  79. ** Revision 1.1 2004/10/20 17:04:00 fwarmerdam
  80. ** New
  81. **
  82. ** Revision 2.3 2004/04/07 17:18:32 gie
  83. ** corrected comment stamp
  84. **
  85. ** Revision 2.2 2003/08/05 00:15:09 gie
  86. ** corrected 0 rho on inverse.
  87. **
  88. ** Revision 2.1 2003/03/28 01:46:02 gie
  89. ** Initial
  90. **
  91. */