sterea.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import gauss from './gauss';
  2. import adjust_lon from '../common/adjust_lon';
  3. export function init() {
  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. export function forward(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. export function inverse(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. export var names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative","Double_Stereographic"];
  53. export default {
  54. init: init,
  55. forward: forward,
  56. inverse: inverse,
  57. names: names
  58. };