EllipsoidGeodesic-72f01b70.js 16 KB

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