EllipsoidGeodesic-2a1a77d2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './when-e6985d2a', './Check-24cae389', './Math-392d0035', './Cartesian2-a5d6dde9'], function (exports, when, Check, _Math, Cartesian2) { 'use strict';
  3. function setConstants(ellipsoidGeodesic) {
  4. var uSquared = ellipsoidGeodesic._uSquared;
  5. var a = ellipsoidGeodesic._ellipsoid.maximumRadius;
  6. var b = ellipsoidGeodesic._ellipsoid.minimumRadius;
  7. var f = (a - b) / a;
  8. var cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);
  9. var sineHeading = Math.sin(ellipsoidGeodesic._startHeading);
  10. var tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);
  11. var cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);
  12. var sineU = cosineU * tanU;
  13. var sigma = Math.atan2(tanU, cosineHeading);
  14. var sineAlpha = cosineU * sineHeading;
  15. var sineSquaredAlpha = sineAlpha * sineAlpha;
  16. var cosineSquaredAlpha = 1.0 - sineSquaredAlpha;
  17. var cosineAlpha = Math.sqrt(cosineSquaredAlpha);
  18. var u2Over4 = uSquared / 4.0;
  19. var u4Over16 = u2Over4 * u2Over4;
  20. var u6Over64 = u4Over16 * u2Over4;
  21. var u8Over256 = u4Over16 * u4Over16;
  22. var 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. var a1 = 1.0 - u2Over4 + (15.0 * u4Over16) / 8.0 - (35.0 * u6Over64) / 8.0;
  29. var a2 = 1.0 - 3.0 * u2Over4 + (35.0 * u4Over16) / 4.0;
  30. var a3 = 1.0 - 5.0 * u2Over4;
  31. var 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. var 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. var 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. var eff = (major - minor) / major;
  100. var l = secondLongitude - firstLongitude;
  101. var u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));
  102. var u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));
  103. var cosineU1 = Math.cos(u1);
  104. var sineU1 = Math.sin(u1);
  105. var cosineU2 = Math.cos(u2);
  106. var sineU2 = Math.sin(u2);
  107. var cc = cosineU1 * cosineU2;
  108. var cs = cosineU1 * sineU2;
  109. var ss = sineU1 * sineU2;
  110. var sc = sineU1 * cosineU2;
  111. var lambda = l;
  112. var lambdaDot = _Math.CesiumMath.TWO_PI;
  113. var cosineLambda = Math.cos(lambda);
  114. var sineLambda = Math.sin(lambda);
  115. var sigma;
  116. var cosineSigma;
  117. var sineSigma;
  118. var cosineSquaredAlpha;
  119. var cosineTwiceSigmaMidpoint;
  120. do {
  121. cosineLambda = Math.cos(lambda);
  122. sineLambda = Math.sin(lambda);
  123. var 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. var 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 (isNaN(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) > _Math.CesiumMath.EPSILON12);
  154. var uSquared =
  155. (cosineSquaredAlpha * (major * major - minor * minor)) / (minor * minor);
  156. var A =
  157. 1.0 +
  158. (uSquared *
  159. (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0))) /
  160. 16384.0;
  161. var B =
  162. (uSquared *
  163. (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0))) /
  164. 1024.0;
  165. var cosineSquaredTwiceSigmaMidpoint =
  166. cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;
  167. var 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. var distance = minor * A * (sigma - deltaSigma);
  180. var startHeading = Math.atan2(cosineU2 * sineLambda, cs - sc * cosineLambda);
  181. var endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);
  182. ellipsoidGeodesic._distance = distance;
  183. ellipsoidGeodesic._startHeading = startHeading;
  184. ellipsoidGeodesic._endHeading = endHeading;
  185. ellipsoidGeodesic._uSquared = uSquared;
  186. }
  187. var scratchCart1 = new Cartesian2.Cartesian3();
  188. var scratchCart2 = new Cartesian2.Cartesian3();
  189. function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
  190. var firstCartesian = Cartesian2.Cartesian3.normalize(
  191. ellipsoid.cartographicToCartesian(start, scratchCart2),
  192. scratchCart1
  193. );
  194. var lastCartesian = Cartesian2.Cartesian3.normalize(
  195. ellipsoid.cartographicToCartesian(end, scratchCart2),
  196. scratchCart2
  197. );
  198. //>>includeStart('debug', pragmas.debug);
  199. Check.Check.typeOf.number.greaterThanOrEquals(
  200. "value",
  201. Math.abs(
  202. Math.abs(Cartesian2.Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI
  203. ),
  204. 0.0125
  205. );
  206. //>>includeEnd('debug');
  207. vincentyInverseFormula(
  208. ellipsoidGeodesic,
  209. ellipsoid.maximumRadius,
  210. ellipsoid.minimumRadius,
  211. start.longitude,
  212. start.latitude,
  213. end.longitude,
  214. end.latitude
  215. );
  216. ellipsoidGeodesic._start = Cartesian2.Cartographic.clone(
  217. start,
  218. ellipsoidGeodesic._start
  219. );
  220. ellipsoidGeodesic._end = Cartesian2.Cartographic.clone(end, ellipsoidGeodesic._end);
  221. ellipsoidGeodesic._start.height = 0;
  222. ellipsoidGeodesic._end.height = 0;
  223. setConstants(ellipsoidGeodesic);
  224. }
  225. /**
  226. * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.
  227. *
  228. * @alias EllipsoidGeodesic
  229. * @constructor
  230. *
  231. * @param {Cartographic} [start] The initial planetodetic point on the path.
  232. * @param {Cartographic} [end] The final planetodetic point on the path.
  233. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.
  234. */
  235. function EllipsoidGeodesic(start, end, ellipsoid) {
  236. var e = when.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  237. this._ellipsoid = e;
  238. this._start = new Cartesian2.Cartographic();
  239. this._end = new Cartesian2.Cartographic();
  240. this._constants = {};
  241. this._startHeading = undefined;
  242. this._endHeading = undefined;
  243. this._distance = undefined;
  244. this._uSquared = undefined;
  245. if (when.defined(start) && when.defined(end)) {
  246. computeProperties(this, start, end, e);
  247. }
  248. }
  249. Object.defineProperties(EllipsoidGeodesic.prototype, {
  250. /**
  251. * Gets the ellipsoid.
  252. * @memberof EllipsoidGeodesic.prototype
  253. * @type {Ellipsoid}
  254. * @readonly
  255. */
  256. ellipsoid: {
  257. get: function () {
  258. return this._ellipsoid;
  259. },
  260. },
  261. /**
  262. * Gets the surface distance between the start and end point
  263. * @memberof EllipsoidGeodesic.prototype
  264. * @type {Number}
  265. * @readonly
  266. */
  267. surfaceDistance: {
  268. get: function () {
  269. //>>includeStart('debug', pragmas.debug);
  270. Check.Check.defined("distance", this._distance);
  271. //>>includeEnd('debug');
  272. return this._distance;
  273. },
  274. },
  275. /**
  276. * Gets the initial planetodetic point on the path.
  277. * @memberof EllipsoidGeodesic.prototype
  278. * @type {Cartographic}
  279. * @readonly
  280. */
  281. start: {
  282. get: function () {
  283. return this._start;
  284. },
  285. },
  286. /**
  287. * Gets the final planetodetic point on the path.
  288. * @memberof EllipsoidGeodesic.prototype
  289. * @type {Cartographic}
  290. * @readonly
  291. */
  292. end: {
  293. get: function () {
  294. return this._end;
  295. },
  296. },
  297. /**
  298. * Gets the heading at the initial point.
  299. * @memberof EllipsoidGeodesic.prototype
  300. * @type {Number}
  301. * @readonly
  302. */
  303. startHeading: {
  304. get: function () {
  305. //>>includeStart('debug', pragmas.debug);
  306. Check.Check.defined("distance", this._distance);
  307. //>>includeEnd('debug');
  308. return this._startHeading;
  309. },
  310. },
  311. /**
  312. * Gets the heading at the final point.
  313. * @memberof EllipsoidGeodesic.prototype
  314. * @type {Number}
  315. * @readonly
  316. */
  317. endHeading: {
  318. get: function () {
  319. //>>includeStart('debug', pragmas.debug);
  320. Check.Check.defined("distance", this._distance);
  321. //>>includeEnd('debug');
  322. return this._endHeading;
  323. },
  324. },
  325. });
  326. /**
  327. * Sets the start and end points of the geodesic
  328. *
  329. * @param {Cartographic} start The initial planetodetic point on the path.
  330. * @param {Cartographic} end The final planetodetic point on the path.
  331. */
  332. EllipsoidGeodesic.prototype.setEndPoints = function (start, end) {
  333. //>>includeStart('debug', pragmas.debug);
  334. Check.Check.defined("start", start);
  335. Check.Check.defined("end", end);
  336. //>>includeEnd('debug');
  337. computeProperties(this, start, end, this._ellipsoid);
  338. };
  339. /**
  340. * Provides the location of a point at the indicated portion along the geodesic.
  341. *
  342. * @param {Number} fraction The portion of the distance between the initial and final points.
  343. * @param {Cartographic} [result] The object in which to store the result.
  344. * @returns {Cartographic} The location of the point along the geodesic.
  345. */
  346. EllipsoidGeodesic.prototype.interpolateUsingFraction = function (
  347. fraction,
  348. result
  349. ) {
  350. return this.interpolateUsingSurfaceDistance(
  351. this._distance * fraction,
  352. result
  353. );
  354. };
  355. /**
  356. * Provides the location of a point at the indicated distance along the geodesic.
  357. *
  358. * @param {Number} distance The distance from the inital point to the point of interest along the geodesic
  359. * @param {Cartographic} [result] The object in which to store the result.
  360. * @returns {Cartographic} The location of the point along the geodesic.
  361. *
  362. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  363. */
  364. EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function (
  365. distance,
  366. result
  367. ) {
  368. //>>includeStart('debug', pragmas.debug);
  369. Check.Check.defined("distance", this._distance);
  370. //>>includeEnd('debug');
  371. var constants = this._constants;
  372. var s = constants.distanceRatio + distance / constants.b;
  373. var cosine2S = Math.cos(2.0 * s);
  374. var cosine4S = Math.cos(4.0 * s);
  375. var cosine6S = Math.cos(6.0 * s);
  376. var sine2S = Math.sin(2.0 * s);
  377. var sine4S = Math.sin(4.0 * s);
  378. var sine6S = Math.sin(6.0 * s);
  379. var sine8S = Math.sin(8.0 * s);
  380. var s2 = s * s;
  381. var s3 = s * s2;
  382. var u8Over256 = constants.u8Over256;
  383. var u2Over4 = constants.u2Over4;
  384. var u6Over64 = constants.u6Over64;
  385. var u4Over16 = constants.u4Over16;
  386. var sigma =
  387. (2.0 * s3 * u8Over256 * cosine2S) / 3.0 +
  388. s *
  389. (1.0 -
  390. u2Over4 +
  391. (7.0 * u4Over16) / 4.0 -
  392. (15.0 * u6Over64) / 4.0 +
  393. (579.0 * u8Over256) / 64.0 -
  394. (u4Over16 - (15.0 * u6Over64) / 4.0 + (187.0 * u8Over256) / 16.0) *
  395. cosine2S -
  396. ((5.0 * u6Over64) / 4.0 - (115.0 * u8Over256) / 16.0) * cosine4S -
  397. (29.0 * u8Over256 * cosine6S) / 16.0) +
  398. (u2Over4 / 2.0 -
  399. u4Over16 +
  400. (71.0 * u6Over64) / 32.0 -
  401. (85.0 * u8Over256) / 16.0) *
  402. sine2S +
  403. ((5.0 * u4Over16) / 16.0 -
  404. (5.0 * u6Over64) / 4.0 +
  405. (383.0 * u8Over256) / 96.0) *
  406. sine4S -
  407. s2 *
  408. ((u6Over64 - (11.0 * u8Over256) / 2.0) * sine2S +
  409. (5.0 * u8Over256 * sine4S) / 2.0) +
  410. ((29.0 * u6Over64) / 96.0 - (29.0 * u8Over256) / 16.0) * sine6S +
  411. (539.0 * u8Over256 * sine8S) / 1536.0;
  412. var theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);
  413. var latitude = Math.atan((constants.a / constants.b) * Math.tan(theta));
  414. // Redefine in terms of relative argument of latitude.
  415. sigma = sigma - constants.sigma;
  416. var cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);
  417. var sineSigma = Math.sin(sigma);
  418. var cosineSigma = Math.cos(sigma);
  419. var cc = constants.cosineU * cosineSigma;
  420. var ss = constants.sineU * sineSigma;
  421. var lambda = Math.atan2(
  422. sineSigma * constants.sineHeading,
  423. cc - ss * constants.cosineHeading
  424. );
  425. var l =
  426. lambda -
  427. computeDeltaLambda(
  428. constants.f,
  429. constants.sineAlpha,
  430. constants.cosineSquaredAlpha,
  431. sigma,
  432. sineSigma,
  433. cosineSigma,
  434. cosineTwiceSigmaMidpoint
  435. );
  436. if (when.defined(result)) {
  437. result.longitude = this._start.longitude + l;
  438. result.latitude = latitude;
  439. result.height = 0.0;
  440. return result;
  441. }
  442. return new Cartesian2.Cartographic(this._start.longitude + l, latitude, 0.0);
  443. };
  444. exports.EllipsoidGeodesic = EllipsoidGeodesic;
  445. });