cass.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import mlfn from '../common/mlfn';
  2. import e0fn from '../common/e0fn';
  3. import e1fn from '../common/e1fn';
  4. import e2fn from '../common/e2fn';
  5. import e3fn from '../common/e3fn';
  6. import gN from '../common/gN';
  7. import adjust_lon from '../common/adjust_lon';
  8. import adjust_lat from '../common/adjust_lat';
  9. import imlfn from '../common/imlfn';
  10. import {HALF_PI, EPSLN} from '../constants/values';
  11. export function init() {
  12. if (!this.sphere) {
  13. this.e0 = e0fn(this.es);
  14. this.e1 = e1fn(this.es);
  15. this.e2 = e2fn(this.es);
  16. this.e3 = e3fn(this.es);
  17. this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  18. }
  19. }
  20. /* Cassini forward equations--mapping lat,long to x,y
  21. -----------------------------------------------------------------------*/
  22. export function forward(p) {
  23. /* Forward equations
  24. -----------------*/
  25. var x, y;
  26. var lam = p.x;
  27. var phi = p.y;
  28. lam = adjust_lon(lam - this.long0);
  29. if (this.sphere) {
  30. x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
  31. y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
  32. }
  33. else {
  34. //ellipsoid
  35. var sinphi = Math.sin(phi);
  36. var cosphi = Math.cos(phi);
  37. var nl = gN(this.a, this.e, sinphi);
  38. var tl = Math.tan(phi) * Math.tan(phi);
  39. var al = lam * Math.cos(phi);
  40. var asq = al * al;
  41. var cl = this.es * cosphi * cosphi / (1 - this.es);
  42. var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
  43. x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
  44. y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
  45. }
  46. p.x = x + this.x0;
  47. p.y = y + this.y0;
  48. return p;
  49. }
  50. /* Inverse equations
  51. -----------------*/
  52. export function inverse(p) {
  53. p.x -= this.x0;
  54. p.y -= this.y0;
  55. var x = p.x / this.a;
  56. var y = p.y / this.a;
  57. var phi, lam;
  58. if (this.sphere) {
  59. var dd = y + this.lat0;
  60. phi = Math.asin(Math.sin(dd) * Math.cos(x));
  61. lam = Math.atan2(Math.tan(x), Math.cos(dd));
  62. }
  63. else {
  64. /* ellipsoid */
  65. var ml1 = this.ml0 / this.a + y;
  66. var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
  67. if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
  68. p.x = this.long0;
  69. p.y = HALF_PI;
  70. if (y < 0) {
  71. p.y *= -1;
  72. }
  73. return p;
  74. }
  75. var nl1 = gN(this.a, this.e, Math.sin(phi1));
  76. var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
  77. var tl1 = Math.pow(Math.tan(phi1), 2);
  78. var dl = x * this.a / nl1;
  79. var dsq = dl * dl;
  80. phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
  81. lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
  82. }
  83. p.x = adjust_lon(lam + this.long0);
  84. p.y = adjust_lat(phi);
  85. return p;
  86. }
  87. export var names = ["Cassini", "Cassini_Soldner", "cass"];
  88. export default {
  89. init: init,
  90. forward: forward,
  91. inverse: inverse,
  92. names: names
  93. };