EllipsoidRhumbLine-ef872433.js 23 KB

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