sterea.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var gauss = require('./gauss');
  2. var adjust_lon = require('../common/adjust_lon');
  3. exports.init = function() {
  4. gauss.init.apply(this);
  5. if (!this.rc) {
  6. return;
  7. }
  8. this.sinc0 = Math.sin(this.phic0);
  9. this.cosc0 = Math.cos(this.phic0);
  10. this.R2 = 2 * this.rc;
  11. if (!this.title) {
  12. this.title = "Oblique Stereographic Alternative";
  13. }
  14. };
  15. exports.forward = function(p) {
  16. var sinc, cosc, cosl, k;
  17. p.x = adjust_lon(p.x - this.long0);
  18. gauss.forward.apply(this, [p]);
  19. sinc = Math.sin(p.y);
  20. cosc = Math.cos(p.y);
  21. cosl = Math.cos(p.x);
  22. k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
  23. p.x = k * cosc * Math.sin(p.x);
  24. p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
  25. p.x = this.a * p.x + this.x0;
  26. p.y = this.a * p.y + this.y0;
  27. return p;
  28. };
  29. exports.inverse = function(p) {
  30. var sinc, cosc, lon, lat, rho;
  31. p.x = (p.x - this.x0) / this.a;
  32. p.y = (p.y - this.y0) / this.a;
  33. p.x /= this.k0;
  34. p.y /= this.k0;
  35. if ((rho = Math.sqrt(p.x * p.x + p.y * p.y))) {
  36. var c = 2 * Math.atan2(rho, this.R2);
  37. sinc = Math.sin(c);
  38. cosc = Math.cos(c);
  39. lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
  40. lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
  41. }
  42. else {
  43. lat = this.phic0;
  44. lon = 0;
  45. }
  46. p.x = lon;
  47. p.y = lat;
  48. gauss.inverse.apply(this, [p]);
  49. p.x = adjust_lon(p.x + this.long0);
  50. return p;
  51. };
  52. exports.names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];