EllipsoidRhumbLine-d049f903.js 24 KB

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