EllipsoidGeodesic-98096082.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './Matrix2-69c32d33', './RuntimeError-c581ca93', './defaultValue-94c3e563', './ComponentDatatype-b1ea011a'], (function (exports, Matrix2, RuntimeError, defaultValue, ComponentDatatype) { 'use strict';
  3. function setConstants(ellipsoidGeodesic) {
  4. const uSquared = ellipsoidGeodesic._uSquared;
  5. const a = ellipsoidGeodesic._ellipsoid.maximumRadius;
  6. const b = ellipsoidGeodesic._ellipsoid.minimumRadius;
  7. const f = (a - b) / a;
  8. const cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);
  9. const sineHeading = Math.sin(ellipsoidGeodesic._startHeading);
  10. const tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);
  11. const cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);
  12. const sineU = cosineU * tanU;
  13. const sigma = Math.atan2(tanU, cosineHeading);
  14. const sineAlpha = cosineU * sineHeading;
  15. const sineSquaredAlpha = sineAlpha * sineAlpha;
  16. const cosineSquaredAlpha = 1.0 - sineSquaredAlpha;
  17. const cosineAlpha = Math.sqrt(cosineSquaredAlpha);
  18. const u2Over4 = uSquared / 4.0;
  19. const u4Over16 = u2Over4 * u2Over4;
  20. const u6Over64 = u4Over16 * u2Over4;
  21. const u8Over256 = u4Over16 * u4Over16;
  22. const a0 =
  23. 1.0 +
  24. u2Over4 -
  25. (3.0 * u4Over16) / 4.0 +
  26. (5.0 * u6Over64) / 4.0 -
  27. (175.0 * u8Over256) / 64.0;
  28. const a1 = 1.0 - u2Over4 + (15.0 * u4Over16) / 8.0 - (35.0 * u6Over64) / 8.0;
  29. const a2 = 1.0 - 3.0 * u2Over4 + (35.0 * u4Over16) / 4.0;
  30. const a3 = 1.0 - 5.0 * u2Over4;
  31. const distanceRatio =
  32. a0 * sigma -
  33. (a1 * Math.sin(2.0 * sigma) * u2Over4) / 2.0 -
  34. (a2 * Math.sin(4.0 * sigma) * u4Over16) / 16.0 -
  35. (a3 * Math.sin(6.0 * sigma) * u6Over64) / 48.0 -
  36. (Math.sin(8.0 * sigma) * 5.0 * u8Over256) / 512;
  37. const constants = ellipsoidGeodesic._constants;
  38. constants.a = a;
  39. constants.b = b;
  40. constants.f = f;
  41. constants.cosineHeading = cosineHeading;
  42. constants.sineHeading = sineHeading;
  43. constants.tanU = tanU;
  44. constants.cosineU = cosineU;
  45. constants.sineU = sineU;
  46. constants.sigma = sigma;
  47. constants.sineAlpha = sineAlpha;
  48. constants.sineSquaredAlpha = sineSquaredAlpha;
  49. constants.cosineSquaredAlpha = cosineSquaredAlpha;
  50. constants.cosineAlpha = cosineAlpha;
  51. constants.u2Over4 = u2Over4;
  52. constants.u4Over16 = u4Over16;
  53. constants.u6Over64 = u6Over64;
  54. constants.u8Over256 = u8Over256;
  55. constants.a0 = a0;
  56. constants.a1 = a1;
  57. constants.a2 = a2;
  58. constants.a3 = a3;
  59. constants.distanceRatio = distanceRatio;
  60. }
  61. function computeC(f, cosineSquaredAlpha) {
  62. return (
  63. (f * cosineSquaredAlpha * (4.0 + f * (4.0 - 3.0 * cosineSquaredAlpha))) /
  64. 16.0
  65. );
  66. }
  67. function computeDeltaLambda(
  68. f,
  69. sineAlpha,
  70. cosineSquaredAlpha,
  71. sigma,
  72. sineSigma,
  73. cosineSigma,
  74. cosineTwiceSigmaMidpoint
  75. ) {
  76. const C = computeC(f, cosineSquaredAlpha);
  77. return (
  78. (1.0 - C) *
  79. f *
  80. sineAlpha *
  81. (sigma +
  82. C *
  83. sineSigma *
  84. (cosineTwiceSigmaMidpoint +
  85. C *
  86. cosineSigma *
  87. (2.0 * cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint - 1.0)))
  88. );
  89. }
  90. function vincentyInverseFormula(
  91. ellipsoidGeodesic,
  92. major,
  93. minor,
  94. firstLongitude,
  95. firstLatitude,
  96. secondLongitude,
  97. secondLatitude
  98. ) {
  99. const eff = (major - minor) / major;
  100. const l = secondLongitude - firstLongitude;
  101. const u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));
  102. const u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));
  103. const cosineU1 = Math.cos(u1);
  104. const sineU1 = Math.sin(u1);
  105. const cosineU2 = Math.cos(u2);
  106. const sineU2 = Math.sin(u2);
  107. const cc = cosineU1 * cosineU2;
  108. const cs = cosineU1 * sineU2;
  109. const ss = sineU1 * sineU2;
  110. const sc = sineU1 * cosineU2;
  111. let lambda = l;
  112. let lambdaDot = ComponentDatatype.CesiumMath.TWO_PI;
  113. let cosineLambda = Math.cos(lambda);
  114. let sineLambda = Math.sin(lambda);
  115. let sigma;
  116. let cosineSigma;
  117. let sineSigma;
  118. let cosineSquaredAlpha;
  119. let cosineTwiceSigmaMidpoint;
  120. do {
  121. cosineLambda = Math.cos(lambda);
  122. sineLambda = Math.sin(lambda);
  123. const temp = cs - sc * cosineLambda;
  124. sineSigma = Math.sqrt(
  125. cosineU2 * cosineU2 * sineLambda * sineLambda + temp * temp
  126. );
  127. cosineSigma = ss + cc * cosineLambda;
  128. sigma = Math.atan2(sineSigma, cosineSigma);
  129. let sineAlpha;
  130. if (sineSigma === 0.0) {
  131. sineAlpha = 0.0;
  132. cosineSquaredAlpha = 1.0;
  133. } else {
  134. sineAlpha = (cc * sineLambda) / sineSigma;
  135. cosineSquaredAlpha = 1.0 - sineAlpha * sineAlpha;
  136. }
  137. lambdaDot = lambda;
  138. cosineTwiceSigmaMidpoint = cosineSigma - (2.0 * ss) / cosineSquaredAlpha;
  139. if (!isFinite(cosineTwiceSigmaMidpoint)) {
  140. cosineTwiceSigmaMidpoint = 0.0;
  141. }
  142. lambda =
  143. l +
  144. computeDeltaLambda(
  145. eff,
  146. sineAlpha,
  147. cosineSquaredAlpha,
  148. sigma,
  149. sineSigma,
  150. cosineSigma,
  151. cosineTwiceSigmaMidpoint
  152. );
  153. } while (Math.abs(lambda - lambdaDot) > ComponentDatatype.CesiumMath.EPSILON12);
  154. const uSquared =
  155. (cosineSquaredAlpha * (major * major - minor * minor)) / (minor * minor);
  156. const A =
  157. 1.0 +
  158. (uSquared *
  159. (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0))) /
  160. 16384.0;
  161. const B =
  162. (uSquared *
  163. (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0))) /
  164. 1024.0;
  165. const cosineSquaredTwiceSigmaMidpoint =
  166. cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;
  167. const deltaSigma =
  168. B *
  169. sineSigma *
  170. (cosineTwiceSigmaMidpoint +
  171. (B *
  172. (cosineSigma * (2.0 * cosineSquaredTwiceSigmaMidpoint - 1.0) -
  173. (B *
  174. cosineTwiceSigmaMidpoint *
  175. (4.0 * sineSigma * sineSigma - 3.0) *
  176. (4.0 * cosineSquaredTwiceSigmaMidpoint - 3.0)) /
  177. 6.0)) /
  178. 4.0);
  179. const distance = minor * A * (sigma - deltaSigma);
  180. const startHeading = Math.atan2(
  181. cosineU2 * sineLambda,
  182. cs - sc * cosineLambda
  183. );
  184. const endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);
  185. ellipsoidGeodesic._distance = distance;
  186. ellipsoidGeodesic._startHeading = startHeading;
  187. ellipsoidGeodesic._endHeading = endHeading;
  188. ellipsoidGeodesic._uSquared = uSquared;
  189. }
  190. const scratchCart1 = new Matrix2.Cartesian3();
  191. const scratchCart2 = new Matrix2.Cartesian3();
  192. function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
  193. const firstCartesian = Matrix2.Cartesian3.normalize(
  194. ellipsoid.cartographicToCartesian(start, scratchCart2),
  195. scratchCart1
  196. );
  197. const lastCartesian = Matrix2.Cartesian3.normalize(
  198. ellipsoid.cartographicToCartesian(end, scratchCart2),
  199. scratchCart2
  200. );
  201. //>>includeStart('debug', pragmas.debug);
  202. RuntimeError.Check.typeOf.number.greaterThanOrEquals(
  203. "value",
  204. Math.abs(
  205. Math.abs(Matrix2.Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI
  206. ),
  207. 0.0125
  208. );
  209. //>>includeEnd('debug');
  210. vincentyInverseFormula(
  211. ellipsoidGeodesic,
  212. ellipsoid.maximumRadius,
  213. ellipsoid.minimumRadius,
  214. start.longitude,
  215. start.latitude,
  216. end.longitude,
  217. end.latitude
  218. );
  219. ellipsoidGeodesic._start = Matrix2.Cartographic.clone(
  220. start,
  221. ellipsoidGeodesic._start
  222. );
  223. ellipsoidGeodesic._end = Matrix2.Cartographic.clone(end, ellipsoidGeodesic._end);
  224. ellipsoidGeodesic._start.height = 0;
  225. ellipsoidGeodesic._end.height = 0;
  226. setConstants(ellipsoidGeodesic);
  227. }
  228. /**
  229. * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.
  230. *
  231. * @alias EllipsoidGeodesic
  232. * @constructor
  233. *
  234. * @param {Cartographic} [start] The initial planetodetic point on the path.
  235. * @param {Cartographic} [end] The final planetodetic point on the path.
  236. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.
  237. */
  238. function EllipsoidGeodesic(start, end, ellipsoid) {
  239. const e = defaultValue.defaultValue(ellipsoid, Matrix2.Ellipsoid.WGS84);
  240. this._ellipsoid = e;
  241. this._start = new Matrix2.Cartographic();
  242. this._end = new Matrix2.Cartographic();
  243. this._constants = {};
  244. this._startHeading = undefined;
  245. this._endHeading = undefined;
  246. this._distance = undefined;
  247. this._uSquared = undefined;
  248. if (defaultValue.defined(start) && defaultValue.defined(end)) {
  249. computeProperties(this, start, end, e);
  250. }
  251. }
  252. Object.defineProperties(EllipsoidGeodesic.prototype, {
  253. /**
  254. * Gets the ellipsoid.
  255. * @memberof EllipsoidGeodesic.prototype
  256. * @type {Ellipsoid}
  257. * @readonly
  258. */
  259. ellipsoid: {
  260. get: function () {
  261. return this._ellipsoid;
  262. },
  263. },
  264. /**
  265. * Gets the surface distance between the start and end point
  266. * @memberof EllipsoidGeodesic.prototype
  267. * @type {Number}
  268. * @readonly
  269. */
  270. surfaceDistance: {
  271. get: function () {
  272. //>>includeStart('debug', pragmas.debug);
  273. RuntimeError.Check.defined("distance", this._distance);
  274. //>>includeEnd('debug');
  275. return this._distance;
  276. },
  277. },
  278. /**
  279. * Gets the initial planetodetic point on the path.
  280. * @memberof EllipsoidGeodesic.prototype
  281. * @type {Cartographic}
  282. * @readonly
  283. */
  284. start: {
  285. get: function () {
  286. return this._start;
  287. },
  288. },
  289. /**
  290. * Gets the final planetodetic point on the path.
  291. * @memberof EllipsoidGeodesic.prototype
  292. * @type {Cartographic}
  293. * @readonly
  294. */
  295. end: {
  296. get: function () {
  297. return this._end;
  298. },
  299. },
  300. /**
  301. * Gets the heading at the initial point.
  302. * @memberof EllipsoidGeodesic.prototype
  303. * @type {Number}
  304. * @readonly
  305. */
  306. startHeading: {
  307. get: function () {
  308. //>>includeStart('debug', pragmas.debug);
  309. RuntimeError.Check.defined("distance", this._distance);
  310. //>>includeEnd('debug');
  311. return this._startHeading;
  312. },
  313. },
  314. /**
  315. * Gets the heading at the final point.
  316. * @memberof EllipsoidGeodesic.prototype
  317. * @type {Number}
  318. * @readonly
  319. */
  320. endHeading: {
  321. get: function () {
  322. //>>includeStart('debug', pragmas.debug);
  323. RuntimeError.Check.defined("distance", this._distance);
  324. //>>includeEnd('debug');
  325. return this._endHeading;
  326. },
  327. },
  328. });
  329. /**
  330. * Sets the start and end points of the geodesic
  331. *
  332. * @param {Cartographic} start The initial planetodetic point on the path.
  333. * @param {Cartographic} end The final planetodetic point on the path.
  334. */
  335. EllipsoidGeodesic.prototype.setEndPoints = function (start, end) {
  336. //>>includeStart('debug', pragmas.debug);
  337. RuntimeError.Check.defined("start", start);
  338. RuntimeError.Check.defined("end", end);
  339. //>>includeEnd('debug');
  340. computeProperties(this, start, end, this._ellipsoid);
  341. };
  342. /**
  343. * Provides the location of a point at the indicated portion along the geodesic.
  344. *
  345. * @param {Number} fraction The portion of the distance between the initial and final points.
  346. * @param {Cartographic} [result] The object in which to store the result.
  347. * @returns {Cartographic} The location of the point along the geodesic.
  348. */
  349. EllipsoidGeodesic.prototype.interpolateUsingFraction = function (
  350. fraction,
  351. result
  352. ) {
  353. return this.interpolateUsingSurfaceDistance(
  354. this._distance * fraction,
  355. result
  356. );
  357. };
  358. /**
  359. * Provides the location of a point at the indicated distance along the geodesic.
  360. *
  361. * @param {Number} distance The distance from the inital point to the point of interest along the geodesic
  362. * @param {Cartographic} [result] The object in which to store the result.
  363. * @returns {Cartographic} The location of the point along the geodesic.
  364. *
  365. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  366. */
  367. EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function (
  368. distance,
  369. result
  370. ) {
  371. //>>includeStart('debug', pragmas.debug);
  372. RuntimeError.Check.defined("distance", this._distance);
  373. //>>includeEnd('debug');
  374. const constants = this._constants;
  375. const s = constants.distanceRatio + distance / constants.b;
  376. const cosine2S = Math.cos(2.0 * s);
  377. const cosine4S = Math.cos(4.0 * s);
  378. const cosine6S = Math.cos(6.0 * s);
  379. const sine2S = Math.sin(2.0 * s);
  380. const sine4S = Math.sin(4.0 * s);
  381. const sine6S = Math.sin(6.0 * s);
  382. const sine8S = Math.sin(8.0 * s);
  383. const s2 = s * s;
  384. const s3 = s * s2;
  385. const u8Over256 = constants.u8Over256;
  386. const u2Over4 = constants.u2Over4;
  387. const u6Over64 = constants.u6Over64;
  388. const u4Over16 = constants.u4Over16;
  389. let sigma =
  390. (2.0 * s3 * u8Over256 * cosine2S) / 3.0 +
  391. s *
  392. (1.0 -
  393. u2Over4 +
  394. (7.0 * u4Over16) / 4.0 -
  395. (15.0 * u6Over64) / 4.0 +
  396. (579.0 * u8Over256) / 64.0 -
  397. (u4Over16 - (15.0 * u6Over64) / 4.0 + (187.0 * u8Over256) / 16.0) *
  398. cosine2S -
  399. ((5.0 * u6Over64) / 4.0 - (115.0 * u8Over256) / 16.0) * cosine4S -
  400. (29.0 * u8Over256 * cosine6S) / 16.0) +
  401. (u2Over4 / 2.0 -
  402. u4Over16 +
  403. (71.0 * u6Over64) / 32.0 -
  404. (85.0 * u8Over256) / 16.0) *
  405. sine2S +
  406. ((5.0 * u4Over16) / 16.0 -
  407. (5.0 * u6Over64) / 4.0 +
  408. (383.0 * u8Over256) / 96.0) *
  409. sine4S -
  410. s2 *
  411. ((u6Over64 - (11.0 * u8Over256) / 2.0) * sine2S +
  412. (5.0 * u8Over256 * sine4S) / 2.0) +
  413. ((29.0 * u6Over64) / 96.0 - (29.0 * u8Over256) / 16.0) * sine6S +
  414. (539.0 * u8Over256 * sine8S) / 1536.0;
  415. const theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);
  416. const latitude = Math.atan((constants.a / constants.b) * Math.tan(theta));
  417. // Redefine in terms of relative argument of latitude.
  418. sigma = sigma - constants.sigma;
  419. const cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);
  420. const sineSigma = Math.sin(sigma);
  421. const cosineSigma = Math.cos(sigma);
  422. const cc = constants.cosineU * cosineSigma;
  423. const ss = constants.sineU * sineSigma;
  424. const lambda = Math.atan2(
  425. sineSigma * constants.sineHeading,
  426. cc - ss * constants.cosineHeading
  427. );
  428. const l =
  429. lambda -
  430. computeDeltaLambda(
  431. constants.f,
  432. constants.sineAlpha,
  433. constants.cosineSquaredAlpha,
  434. sigma,
  435. sineSigma,
  436. cosineSigma,
  437. cosineTwiceSigmaMidpoint
  438. );
  439. if (defaultValue.defined(result)) {
  440. result.longitude = this._start.longitude + l;
  441. result.latitude = latitude;
  442. result.height = 0.0;
  443. return result;
  444. }
  445. return new Matrix2.Cartographic(this._start.longitude + l, latitude, 0.0);
  446. };
  447. exports.EllipsoidGeodesic = EllipsoidGeodesic;
  448. }));