EllipsoidRhumbLine-7bc7dfce.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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 calculateM(ellipticity, major, latitude) {
  27. if (ellipticity === 0.0) {
  28. // sphere
  29. return major * latitude;
  30. }
  31. const e2 = ellipticity * ellipticity;
  32. const e4 = e2 * e2;
  33. const e6 = e4 * e2;
  34. const e8 = e6 * e2;
  35. const e10 = e8 * e2;
  36. const e12 = e10 * e2;
  37. const phi = latitude;
  38. const sin2Phi = Math.sin(2 * phi);
  39. const sin4Phi = Math.sin(4 * phi);
  40. const sin6Phi = Math.sin(6 * phi);
  41. const sin8Phi = Math.sin(8 * phi);
  42. const sin10Phi = Math.sin(10 * phi);
  43. const sin12Phi = Math.sin(12 * phi);
  44. return (
  45. major *
  46. ((1 -
  47. e2 / 4 -
  48. (3 * e4) / 64 -
  49. (5 * e6) / 256 -
  50. (175 * e8) / 16384 -
  51. (441 * e10) / 65536 -
  52. (4851 * e12) / 1048576) *
  53. phi -
  54. ((3 * e2) / 8 +
  55. (3 * e4) / 32 +
  56. (45 * e6) / 1024 +
  57. (105 * e8) / 4096 +
  58. (2205 * e10) / 131072 +
  59. (6237 * e12) / 524288) *
  60. sin2Phi +
  61. ((15 * e4) / 256 +
  62. (45 * e6) / 1024 +
  63. (525 * e8) / 16384 +
  64. (1575 * e10) / 65536 +
  65. (155925 * e12) / 8388608) *
  66. sin4Phi -
  67. ((35 * e6) / 3072 +
  68. (175 * e8) / 12288 +
  69. (3675 * e10) / 262144 +
  70. (13475 * e12) / 1048576) *
  71. sin6Phi +
  72. ((315 * e8) / 131072 + (2205 * e10) / 524288 + (43659 * e12) / 8388608) *
  73. sin8Phi -
  74. ((693 * e10) / 1310720 + (6237 * e12) / 5242880) * sin10Phi +
  75. ((1001 * e12) / 8388608) * sin12Phi)
  76. );
  77. }
  78. function calculateInverseM(M, ellipticity, major) {
  79. const d = M / major;
  80. if (ellipticity === 0.0) {
  81. // sphere
  82. return d;
  83. }
  84. const d2 = d * d;
  85. const d3 = d2 * d;
  86. const d4 = d3 * d;
  87. const e = ellipticity;
  88. const e2 = e * e;
  89. const e4 = e2 * e2;
  90. const e6 = e4 * e2;
  91. const e8 = e6 * e2;
  92. const e10 = e8 * e2;
  93. const e12 = e10 * e2;
  94. const sin2D = Math.sin(2 * d);
  95. const cos2D = Math.cos(2 * d);
  96. const sin4D = Math.sin(4 * d);
  97. const cos4D = Math.cos(4 * d);
  98. const sin6D = Math.sin(6 * d);
  99. const cos6D = Math.cos(6 * d);
  100. const sin8D = Math.sin(8 * d);
  101. const cos8D = Math.cos(8 * d);
  102. const sin10D = Math.sin(10 * d);
  103. const cos10D = Math.cos(10 * d);
  104. const sin12D = Math.sin(12 * d);
  105. return (
  106. d +
  107. (d * e2) / 4 +
  108. (7 * d * e4) / 64 +
  109. (15 * d * e6) / 256 +
  110. (579 * d * e8) / 16384 +
  111. (1515 * d * e10) / 65536 +
  112. (16837 * d * e12) / 1048576 +
  113. ((3 * d * e4) / 16 +
  114. (45 * d * e6) / 256 -
  115. (d * (32 * d2 - 561) * e8) / 4096 -
  116. (d * (232 * d2 - 1677) * e10) / 16384 +
  117. (d * (399985 - 90560 * d2 + 512 * d4) * e12) / 5242880) *
  118. cos2D +
  119. ((21 * d * e6) / 256 +
  120. (483 * d * e8) / 4096 -
  121. (d * (224 * d2 - 1969) * e10) / 16384 -
  122. (d * (33152 * d2 - 112599) * e12) / 1048576) *
  123. cos4D +
  124. ((151 * d * e8) / 4096 +
  125. (4681 * d * e10) / 65536 +
  126. (1479 * d * e12) / 16384 -
  127. (453 * d3 * e12) / 32768) *
  128. cos6D +
  129. ((1097 * d * e10) / 65536 + (42783 * d * e12) / 1048576) * cos8D +
  130. ((8011 * d * e12) / 1048576) * cos10D +
  131. ((3 * e2) / 8 +
  132. (3 * e4) / 16 +
  133. (213 * e6) / 2048 -
  134. (3 * d2 * e6) / 64 +
  135. (255 * e8) / 4096 -
  136. (33 * d2 * e8) / 512 +
  137. (20861 * e10) / 524288 -
  138. (33 * d2 * e10) / 512 +
  139. (d4 * e10) / 1024 +
  140. (28273 * e12) / 1048576 -
  141. (471 * d2 * e12) / 8192 +
  142. (9 * d4 * e12) / 4096) *
  143. sin2D +
  144. ((21 * e4) / 256 +
  145. (21 * e6) / 256 +
  146. (533 * e8) / 8192 -
  147. (21 * d2 * e8) / 512 +
  148. (197 * e10) / 4096 -
  149. (315 * d2 * e10) / 4096 +
  150. (584039 * e12) / 16777216 -
  151. (12517 * d2 * e12) / 131072 +
  152. (7 * d4 * e12) / 2048) *
  153. sin4D +
  154. ((151 * e6) / 6144 +
  155. (151 * e8) / 4096 +
  156. (5019 * e10) / 131072 -
  157. (453 * d2 * e10) / 16384 +
  158. (26965 * e12) / 786432 -
  159. (8607 * d2 * e12) / 131072) *
  160. sin6D +
  161. ((1097 * e8) / 131072 +
  162. (1097 * e10) / 65536 +
  163. (225797 * e12) / 10485760 -
  164. (1097 * d2 * e12) / 65536) *
  165. sin8D +
  166. ((8011 * e10) / 2621440 + (8011 * e12) / 1048576) * sin10D +
  167. ((293393 * e12) / 251658240) * sin12D
  168. );
  169. }
  170. function calculateSigma(ellipticity, latitude) {
  171. if (ellipticity === 0.0) {
  172. // sphere
  173. return Math.log(Math.tan(0.5 * (ComponentDatatype.CesiumMath.PI_OVER_TWO + latitude)));
  174. }
  175. const eSinL = ellipticity * Math.sin(latitude);
  176. return (
  177. Math.log(Math.tan(0.5 * (ComponentDatatype.CesiumMath.PI_OVER_TWO + latitude))) -
  178. (ellipticity / 2.0) * Math.log((1 + eSinL) / (1 - eSinL))
  179. );
  180. }
  181. function calculateHeading(
  182. ellipsoidRhumbLine,
  183. firstLongitude,
  184. firstLatitude,
  185. secondLongitude,
  186. secondLatitude
  187. ) {
  188. const sigma1 = calculateSigma(ellipsoidRhumbLine._ellipticity, firstLatitude);
  189. const sigma2 = calculateSigma(
  190. ellipsoidRhumbLine._ellipticity,
  191. secondLatitude
  192. );
  193. return Math.atan2(
  194. ComponentDatatype.CesiumMath.negativePiToPi(secondLongitude - firstLongitude),
  195. sigma2 - sigma1
  196. );
  197. }
  198. function calculateArcLength(
  199. ellipsoidRhumbLine,
  200. major,
  201. minor,
  202. firstLongitude,
  203. firstLatitude,
  204. secondLongitude,
  205. secondLatitude
  206. ) {
  207. const heading = ellipsoidRhumbLine._heading;
  208. const deltaLongitude = secondLongitude - firstLongitude;
  209. let distance = 0.0;
  210. //Check to see if the rhumb line has constant latitude
  211. //This equation will diverge if heading gets close to 90 degrees
  212. if (
  213. ComponentDatatype.CesiumMath.equalsEpsilon(
  214. Math.abs(heading),
  215. ComponentDatatype.CesiumMath.PI_OVER_TWO,
  216. ComponentDatatype.CesiumMath.EPSILON8
  217. )
  218. ) {
  219. //If heading is close to 90 degrees
  220. if (major === minor) {
  221. distance =
  222. major *
  223. Math.cos(firstLatitude) *
  224. ComponentDatatype.CesiumMath.negativePiToPi(deltaLongitude);
  225. } else {
  226. const sinPhi = Math.sin(firstLatitude);
  227. distance =
  228. (major *
  229. Math.cos(firstLatitude) *
  230. ComponentDatatype.CesiumMath.negativePiToPi(deltaLongitude)) /
  231. Math.sqrt(1 - ellipsoidRhumbLine._ellipticitySquared * sinPhi * sinPhi);
  232. }
  233. } else {
  234. const M1 = calculateM(
  235. ellipsoidRhumbLine._ellipticity,
  236. major,
  237. firstLatitude
  238. );
  239. const M2 = calculateM(
  240. ellipsoidRhumbLine._ellipticity,
  241. major,
  242. secondLatitude
  243. );
  244. distance = (M2 - M1) / Math.cos(heading);
  245. }
  246. return Math.abs(distance);
  247. }
  248. const scratchCart1 = new Matrix2.Cartesian3();
  249. const scratchCart2 = new Matrix2.Cartesian3();
  250. function computeProperties(ellipsoidRhumbLine, start, end, ellipsoid) {
  251. const firstCartesian = Matrix2.Cartesian3.normalize(
  252. ellipsoid.cartographicToCartesian(start, scratchCart2),
  253. scratchCart1
  254. );
  255. const lastCartesian = Matrix2.Cartesian3.normalize(
  256. ellipsoid.cartographicToCartesian(end, scratchCart2),
  257. scratchCart2
  258. );
  259. //>>includeStart('debug', pragmas.debug);
  260. RuntimeError.Check.typeOf.number.greaterThanOrEquals(
  261. "value",
  262. Math.abs(
  263. Math.abs(Matrix2.Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI
  264. ),
  265. 0.0125
  266. );
  267. //>>includeEnd('debug');
  268. const major = ellipsoid.maximumRadius;
  269. const minor = ellipsoid.minimumRadius;
  270. const majorSquared = major * major;
  271. const minorSquared = minor * minor;
  272. ellipsoidRhumbLine._ellipticitySquared =
  273. (majorSquared - minorSquared) / majorSquared;
  274. ellipsoidRhumbLine._ellipticity = Math.sqrt(
  275. ellipsoidRhumbLine._ellipticitySquared
  276. );
  277. ellipsoidRhumbLine._start = Matrix2.Cartographic.clone(
  278. start,
  279. ellipsoidRhumbLine._start
  280. );
  281. ellipsoidRhumbLine._start.height = 0;
  282. ellipsoidRhumbLine._end = Matrix2.Cartographic.clone(end, ellipsoidRhumbLine._end);
  283. ellipsoidRhumbLine._end.height = 0;
  284. ellipsoidRhumbLine._heading = calculateHeading(
  285. ellipsoidRhumbLine,
  286. start.longitude,
  287. start.latitude,
  288. end.longitude,
  289. end.latitude
  290. );
  291. ellipsoidRhumbLine._distance = calculateArcLength(
  292. ellipsoidRhumbLine,
  293. ellipsoid.maximumRadius,
  294. ellipsoid.minimumRadius,
  295. start.longitude,
  296. start.latitude,
  297. end.longitude,
  298. end.latitude
  299. );
  300. }
  301. function interpolateUsingSurfaceDistance(
  302. start,
  303. heading,
  304. distance,
  305. major,
  306. ellipticity,
  307. result
  308. ) {
  309. if (distance === 0.0) {
  310. return Matrix2.Cartographic.clone(start, result);
  311. }
  312. const ellipticitySquared = ellipticity * ellipticity;
  313. let longitude;
  314. let latitude;
  315. let deltaLongitude;
  316. //Check to see if the rhumb line has constant latitude
  317. //This won't converge if heading is close to 90 degrees
  318. if (
  319. Math.abs(ComponentDatatype.CesiumMath.PI_OVER_TWO - Math.abs(heading)) > ComponentDatatype.CesiumMath.EPSILON8
  320. ) {
  321. //Calculate latitude of the second point
  322. const M1 = calculateM(ellipticity, major, start.latitude);
  323. const deltaM = distance * Math.cos(heading);
  324. const M2 = M1 + deltaM;
  325. latitude = calculateInverseM(M2, ellipticity, major);
  326. //Now find the longitude of the second point
  327. const sigma1 = calculateSigma(ellipticity, start.latitude);
  328. const sigma2 = calculateSigma(ellipticity, latitude);
  329. deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);
  330. longitude = ComponentDatatype.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  331. } else {
  332. //If heading is close to 90 degrees
  333. latitude = start.latitude;
  334. let localRad;
  335. if (ellipticity === 0.0) {
  336. // sphere
  337. localRad = major * Math.cos(start.latitude);
  338. } else {
  339. const sinPhi = Math.sin(start.latitude);
  340. localRad =
  341. (major * Math.cos(start.latitude)) /
  342. Math.sqrt(1 - ellipticitySquared * sinPhi * sinPhi);
  343. }
  344. deltaLongitude = distance / localRad;
  345. if (heading > 0.0) {
  346. longitude = ComponentDatatype.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  347. } else {
  348. longitude = ComponentDatatype.CesiumMath.negativePiToPi(start.longitude - deltaLongitude);
  349. }
  350. }
  351. if (defaultValue.defined(result)) {
  352. result.longitude = longitude;
  353. result.latitude = latitude;
  354. result.height = 0;
  355. return result;
  356. }
  357. return new Matrix2.Cartographic(longitude, latitude, 0);
  358. }
  359. /**
  360. * Initializes a rhumb line on the ellipsoid connecting the two provided planetodetic points.
  361. *
  362. * @alias EllipsoidRhumbLine
  363. * @constructor
  364. *
  365. * @param {Cartographic} [start] The initial planetodetic point on the path.
  366. * @param {Cartographic} [end] The final planetodetic point on the path.
  367. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.
  368. *
  369. * @exception {DeveloperError} angle between start and end must be at least 0.0125 radians.
  370. */
  371. function EllipsoidRhumbLine(start, end, ellipsoid) {
  372. const e = defaultValue.defaultValue(ellipsoid, Matrix2.Ellipsoid.WGS84);
  373. this._ellipsoid = e;
  374. this._start = new Matrix2.Cartographic();
  375. this._end = new Matrix2.Cartographic();
  376. this._heading = undefined;
  377. this._distance = undefined;
  378. this._ellipticity = undefined;
  379. this._ellipticitySquared = undefined;
  380. if (defaultValue.defined(start) && defaultValue.defined(end)) {
  381. computeProperties(this, start, end, e);
  382. }
  383. }
  384. Object.defineProperties(EllipsoidRhumbLine.prototype, {
  385. /**
  386. * Gets the ellipsoid.
  387. * @memberof EllipsoidRhumbLine.prototype
  388. * @type {Ellipsoid}
  389. * @readonly
  390. */
  391. ellipsoid: {
  392. get: function () {
  393. return this._ellipsoid;
  394. },
  395. },
  396. /**
  397. * Gets the surface distance between the start and end point
  398. * @memberof EllipsoidRhumbLine.prototype
  399. * @type {Number}
  400. * @readonly
  401. */
  402. surfaceDistance: {
  403. get: function () {
  404. //>>includeStart('debug', pragmas.debug);
  405. RuntimeError.Check.defined("distance", this._distance);
  406. //>>includeEnd('debug');
  407. return this._distance;
  408. },
  409. },
  410. /**
  411. * Gets the initial planetodetic point on the path.
  412. * @memberof EllipsoidRhumbLine.prototype
  413. * @type {Cartographic}
  414. * @readonly
  415. */
  416. start: {
  417. get: function () {
  418. return this._start;
  419. },
  420. },
  421. /**
  422. * Gets the final planetodetic point on the path.
  423. * @memberof EllipsoidRhumbLine.prototype
  424. * @type {Cartographic}
  425. * @readonly
  426. */
  427. end: {
  428. get: function () {
  429. return this._end;
  430. },
  431. },
  432. /**
  433. * Gets the heading from the start point to the end point.
  434. * @memberof EllipsoidRhumbLine.prototype
  435. * @type {Number}
  436. * @readonly
  437. */
  438. heading: {
  439. get: function () {
  440. //>>includeStart('debug', pragmas.debug);
  441. RuntimeError.Check.defined("distance", this._distance);
  442. //>>includeEnd('debug');
  443. return this._heading;
  444. },
  445. },
  446. });
  447. /**
  448. * Create a rhumb line using an initial position with a heading and distance.
  449. *
  450. * @param {Cartographic} start The initial planetodetic point on the path.
  451. * @param {Number} heading The heading in radians.
  452. * @param {Number} distance The rhumb line distance between the start and end point.
  453. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.
  454. * @param {EllipsoidRhumbLine} [result] The object in which to store the result.
  455. * @returns {EllipsoidRhumbLine} The EllipsoidRhumbLine object.
  456. */
  457. EllipsoidRhumbLine.fromStartHeadingDistance = function (
  458. start,
  459. heading,
  460. distance,
  461. ellipsoid,
  462. result
  463. ) {
  464. //>>includeStart('debug', pragmas.debug);
  465. RuntimeError.Check.defined("start", start);
  466. RuntimeError.Check.defined("heading", heading);
  467. RuntimeError.Check.defined("distance", distance);
  468. RuntimeError.Check.typeOf.number.greaterThan("distance", distance, 0.0);
  469. //>>includeEnd('debug');
  470. const e = defaultValue.defaultValue(ellipsoid, Matrix2.Ellipsoid.WGS84);
  471. const major = e.maximumRadius;
  472. const minor = e.minimumRadius;
  473. const majorSquared = major * major;
  474. const minorSquared = minor * minor;
  475. const ellipticity = Math.sqrt((majorSquared - minorSquared) / majorSquared);
  476. heading = ComponentDatatype.CesiumMath.negativePiToPi(heading);
  477. const end = interpolateUsingSurfaceDistance(
  478. start,
  479. heading,
  480. distance,
  481. e.maximumRadius,
  482. ellipticity
  483. );
  484. if (
  485. !defaultValue.defined(result) ||
  486. (defaultValue.defined(ellipsoid) && !ellipsoid.equals(result.ellipsoid))
  487. ) {
  488. return new EllipsoidRhumbLine(start, end, e);
  489. }
  490. result.setEndPoints(start, end);
  491. return result;
  492. };
  493. /**
  494. * Sets the start and end points of the rhumb line.
  495. *
  496. * @param {Cartographic} start The initial planetodetic point on the path.
  497. * @param {Cartographic} end The final planetodetic point on the path.
  498. */
  499. EllipsoidRhumbLine.prototype.setEndPoints = function (start, end) {
  500. //>>includeStart('debug', pragmas.debug);
  501. RuntimeError.Check.defined("start", start);
  502. RuntimeError.Check.defined("end", end);
  503. //>>includeEnd('debug');
  504. computeProperties(this, start, end, this._ellipsoid);
  505. };
  506. /**
  507. * Provides the location of a point at the indicated portion along the rhumb line.
  508. *
  509. * @param {Number} fraction The portion of the distance between the initial and final points.
  510. * @param {Cartographic} [result] The object in which to store the result.
  511. * @returns {Cartographic} The location of the point along the rhumb line.
  512. */
  513. EllipsoidRhumbLine.prototype.interpolateUsingFraction = function (
  514. fraction,
  515. result
  516. ) {
  517. return this.interpolateUsingSurfaceDistance(
  518. fraction * this._distance,
  519. result
  520. );
  521. };
  522. /**
  523. * Provides the location of a point at the indicated distance along the rhumb line.
  524. *
  525. * @param {Number} distance The distance from the inital point to the point of interest along the rhumbLine.
  526. * @param {Cartographic} [result] The object in which to store the result.
  527. * @returns {Cartographic} The location of the point along the rhumb line.
  528. *
  529. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  530. */
  531. EllipsoidRhumbLine.prototype.interpolateUsingSurfaceDistance = function (
  532. distance,
  533. result
  534. ) {
  535. //>>includeStart('debug', pragmas.debug);
  536. RuntimeError.Check.typeOf.number("distance", distance);
  537. if (!defaultValue.defined(this._distance) || this._distance === 0.0) {
  538. throw new RuntimeError.DeveloperError(
  539. "EllipsoidRhumbLine must have distinct start and end set."
  540. );
  541. }
  542. //>>includeEnd('debug');
  543. return interpolateUsingSurfaceDistance(
  544. this._start,
  545. this._heading,
  546. distance,
  547. this._ellipsoid.maximumRadius,
  548. this._ellipticity,
  549. result
  550. );
  551. };
  552. /**
  553. * Provides the location of a point at the indicated longitude along the rhumb line.
  554. * If the longitude is outside the range of start and end points, the first intersection with the longitude from the start point in the direction of the heading is returned. This follows the spiral property of a rhumb line.
  555. *
  556. * @param {Number} intersectionLongitude The longitude, in radians, at which to find the intersection point from the starting point using the heading.
  557. * @param {Cartographic} [result] The object in which to store the result.
  558. * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.
  559. *
  560. * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.
  561. */
  562. EllipsoidRhumbLine.prototype.findIntersectionWithLongitude = function (
  563. intersectionLongitude,
  564. result
  565. ) {
  566. //>>includeStart('debug', pragmas.debug);
  567. RuntimeError.Check.typeOf.number("intersectionLongitude", intersectionLongitude);
  568. if (!defaultValue.defined(this._distance) || this._distance === 0.0) {
  569. throw new RuntimeError.DeveloperError(
  570. "EllipsoidRhumbLine must have distinct start and end set."
  571. );
  572. }
  573. //>>includeEnd('debug');
  574. const ellipticity = this._ellipticity;
  575. const heading = this._heading;
  576. const absHeading = Math.abs(heading);
  577. const start = this._start;
  578. intersectionLongitude = ComponentDatatype.CesiumMath.negativePiToPi(intersectionLongitude);
  579. if (
  580. ComponentDatatype.CesiumMath.equalsEpsilon(
  581. Math.abs(intersectionLongitude),
  582. Math.PI,
  583. ComponentDatatype.CesiumMath.EPSILON14
  584. )
  585. ) {
  586. intersectionLongitude = ComponentDatatype.CesiumMath.sign(start.longitude) * Math.PI;
  587. }
  588. if (!defaultValue.defined(result)) {
  589. result = new Matrix2.Cartographic();
  590. }
  591. // If heading is -PI/2 or PI/2, this is an E-W rhumb line
  592. // If heading is 0 or PI, this is an N-S rhumb line
  593. if (Math.abs(ComponentDatatype.CesiumMath.PI_OVER_TWO - absHeading) <= ComponentDatatype.CesiumMath.EPSILON8) {
  594. result.longitude = intersectionLongitude;
  595. result.latitude = start.latitude;
  596. result.height = 0;
  597. return result;
  598. } else if (
  599. ComponentDatatype.CesiumMath.equalsEpsilon(
  600. Math.abs(ComponentDatatype.CesiumMath.PI_OVER_TWO - absHeading),
  601. ComponentDatatype.CesiumMath.PI_OVER_TWO,
  602. ComponentDatatype.CesiumMath.EPSILON8
  603. )
  604. ) {
  605. if (
  606. ComponentDatatype.CesiumMath.equalsEpsilon(
  607. intersectionLongitude,
  608. start.longitude,
  609. ComponentDatatype.CesiumMath.EPSILON12
  610. )
  611. ) {
  612. return undefined;
  613. }
  614. result.longitude = intersectionLongitude;
  615. result.latitude =
  616. ComponentDatatype.CesiumMath.PI_OVER_TWO *
  617. ComponentDatatype.CesiumMath.sign(ComponentDatatype.CesiumMath.PI_OVER_TWO - heading);
  618. result.height = 0;
  619. return result;
  620. }
  621. // Use iterative solver from Equation 9 from http://edwilliams.org/ellipsoid/ellipsoid.pdf
  622. const phi1 = start.latitude;
  623. const eSinPhi1 = ellipticity * Math.sin(phi1);
  624. const leftComponent =
  625. Math.tan(0.5 * (ComponentDatatype.CesiumMath.PI_OVER_TWO + phi1)) *
  626. Math.exp((intersectionLongitude - start.longitude) / Math.tan(heading));
  627. const denominator = (1 + eSinPhi1) / (1 - eSinPhi1);
  628. let newPhi = start.latitude;
  629. let phi;
  630. do {
  631. phi = newPhi;
  632. const eSinPhi = ellipticity * Math.sin(phi);
  633. const numerator = (1 + eSinPhi) / (1 - eSinPhi);
  634. newPhi =
  635. 2 *
  636. Math.atan(
  637. leftComponent * Math.pow(numerator / denominator, ellipticity / 2)
  638. ) -
  639. ComponentDatatype.CesiumMath.PI_OVER_TWO;
  640. } while (!ComponentDatatype.CesiumMath.equalsEpsilon(newPhi, phi, ComponentDatatype.CesiumMath.EPSILON12));
  641. result.longitude = intersectionLongitude;
  642. result.latitude = newPhi;
  643. result.height = 0;
  644. return result;
  645. };
  646. /**
  647. * Provides the location of a point at the indicated latitude along the rhumb line.
  648. * If the latitude is outside the range of start and end points, the first intersection with the latitude from that start point in the direction of the heading is returned. This follows the spiral property of a rhumb line.
  649. *
  650. * @param {Number} intersectionLatitude The latitude, in radians, at which to find the intersection point from the starting point using the heading.
  651. * @param {Cartographic} [result] The object in which to store the result.
  652. * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.
  653. *
  654. * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.
  655. */
  656. EllipsoidRhumbLine.prototype.findIntersectionWithLatitude = function (
  657. intersectionLatitude,
  658. result
  659. ) {
  660. //>>includeStart('debug', pragmas.debug);
  661. RuntimeError.Check.typeOf.number("intersectionLatitude", intersectionLatitude);
  662. if (!defaultValue.defined(this._distance) || this._distance === 0.0) {
  663. throw new RuntimeError.DeveloperError(
  664. "EllipsoidRhumbLine must have distinct start and end set."
  665. );
  666. }
  667. //>>includeEnd('debug');
  668. const ellipticity = this._ellipticity;
  669. const heading = this._heading;
  670. const start = this._start;
  671. // If start and end have same latitude, return undefined since it's either no intersection or infinite intersections
  672. if (
  673. ComponentDatatype.CesiumMath.equalsEpsilon(
  674. Math.abs(heading),
  675. ComponentDatatype.CesiumMath.PI_OVER_TWO,
  676. ComponentDatatype.CesiumMath.EPSILON8
  677. )
  678. ) {
  679. return;
  680. }
  681. // Can be solved using the same equations from interpolateUsingSurfaceDistance
  682. const sigma1 = calculateSigma(ellipticity, start.latitude);
  683. const sigma2 = calculateSigma(ellipticity, intersectionLatitude);
  684. const deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);
  685. const longitude = ComponentDatatype.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  686. if (defaultValue.defined(result)) {
  687. result.longitude = longitude;
  688. result.latitude = intersectionLatitude;
  689. result.height = 0;
  690. return result;
  691. }
  692. return new Matrix2.Cartographic(longitude, intersectionLatitude, 0);
  693. };
  694. exports.EllipsoidRhumbLine = EllipsoidRhumbLine;
  695. }));
  696. //# sourceMappingURL=EllipsoidRhumbLine-7bc7dfce.js.map