EllipsoidRhumbLine-f161e674.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2017 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/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['exports', './when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-fe4be337', './Cartesian2-85064f09'], function (exports, when, Check, _Math, Cartographic, Cartesian2) { 'use strict';
  24. function calculateM(ellipticity, major, latitude) {
  25. if (ellipticity === 0.0) { // sphere
  26. return major * latitude;
  27. }
  28. var e2 = ellipticity * ellipticity;
  29. var e4 = e2 * e2;
  30. var e6 = e4 * e2;
  31. var e8 = e6 * e2;
  32. var e10 = e8 * e2;
  33. var e12 = e10 * e2;
  34. var phi = latitude;
  35. var sin2Phi = Math.sin(2 * phi);
  36. var sin4Phi = Math.sin(4 * phi);
  37. var sin6Phi = Math.sin(6 * phi);
  38. var sin8Phi = Math.sin(8 * phi);
  39. var sin10Phi = Math.sin(10 * phi);
  40. var sin12Phi = Math.sin(12 * phi);
  41. return major * ((1 - e2 / 4 - 3 * e4 / 64 - 5 * e6 / 256 - 175 * e8 / 16384 - 441 * e10 / 65536 - 4851 * e12 / 1048576) * phi
  42. - (3 * e2 / 8 + 3 * e4 / 32 + 45 * e6 / 1024 + 105 * e8 / 4096 + 2205 * e10 / 131072 + 6237 * e12 / 524288) * sin2Phi
  43. + (15 * e4 / 256 + 45 * e6 / 1024 + 525 * e8 / 16384 + 1575 * e10 / 65536 + 155925 * e12 / 8388608) * sin4Phi
  44. - (35 * e6 / 3072 + 175 * e8 / 12288 + 3675 * e10 / 262144 + 13475 * e12 / 1048576) * sin6Phi
  45. + (315 * e8 / 131072 + 2205 * e10 / 524288 + 43659 * e12 / 8388608) * sin8Phi
  46. - (693 * e10 / 1310720 + 6237 * e12 / 5242880) * sin10Phi
  47. + 1001 * e12 / 8388608 * sin12Phi);
  48. }
  49. function calculateInverseM(M, ellipticity, major) {
  50. var d = M / major;
  51. if (ellipticity === 0.0) { // sphere
  52. return d;
  53. }
  54. var d2 = d * d;
  55. var d3 = d2 * d;
  56. var d4 = d3 * d;
  57. var e = ellipticity;
  58. var e2 = e * e;
  59. var e4 = e2 * e2;
  60. var e6 = e4 * e2;
  61. var e8 = e6 * e2;
  62. var e10 = e8 * e2;
  63. var e12 = e10 * e2;
  64. var sin2D = Math.sin(2 * d);
  65. var cos2D = Math.cos(2 * d);
  66. var sin4D = Math.sin(4 * d);
  67. var cos4D = Math.cos(4 * d);
  68. var sin6D = Math.sin(6 * d);
  69. var cos6D = Math.cos(6 * d);
  70. var sin8D = Math.sin(8 * d);
  71. var cos8D = Math.cos(8 * d);
  72. var sin10D = Math.sin(10 * d);
  73. var cos10D = Math.cos(10 * d);
  74. var sin12D = Math.sin(12 * d);
  75. return d + d * e2 / 4 + 7 * d * e4 / 64 + 15 * d * e6 / 256 + 579 * d * e8 / 16384 + 1515 * d * e10 / 65536 + 16837 * d * e12 / 1048576
  76. + (3 * d * e4 / 16 + 45 * d * e6 / 256 - d * (32 * d2 - 561) * e8 / 4096 - d * (232 * d2 - 1677) * e10 / 16384 + d * (399985 - 90560 * d2 + 512 * d4) * e12 / 5242880) * cos2D
  77. + (21 * d * e6 / 256 + 483 * d * e8 / 4096 - d * (224 * d2 - 1969) * e10 / 16384 - d * (33152 * d2 - 112599) * e12 / 1048576) * cos4D
  78. + (151 * d * e8 / 4096 + 4681 * d * e10 / 65536 + 1479 * d * e12 / 16384 - 453 * d3 * e12 / 32768) * cos6D
  79. + (1097 * d * e10 / 65536 + 42783 * d * e12 / 1048576) * cos8D
  80. + 8011 * d * e12 / 1048576 * cos10D
  81. + (3 * e2 / 8 + 3 * e4 / 16 + 213 * e6 / 2048 - 3 * d2 * e6 / 64 + 255 * e8 / 4096 - 33 * d2 * e8 / 512 + 20861 * e10 / 524288 - 33 * d2 * e10 / 512 + d4 * e10 / 1024 + 28273 * e12 / 1048576 - 471 * d2 * e12 / 8192 + 9 * d4 * e12 / 4096) * sin2D
  82. + (21 * e4 / 256 + 21 * e6 / 256 + 533 * e8 / 8192 - 21 * d2 * e8 / 512 + 197 * e10 / 4096 - 315 * d2 * e10 / 4096 + 584039 * e12 / 16777216 - 12517 * d2 * e12 / 131072 + 7 * d4 * e12 / 2048) * sin4D
  83. + (151 * e6 / 6144 + 151 * e8 / 4096 + 5019 * e10 / 131072 - 453 * d2 * e10 / 16384 + 26965 * e12 / 786432 - 8607 * d2 * e12 / 131072) * sin6D
  84. + (1097 * e8 / 131072 + 1097 * e10 / 65536 + 225797 * e12 / 10485760 - 1097 * d2 * e12 / 65536) * sin8D
  85. + (8011 * e10 / 2621440 + 8011 * e12 / 1048576) * sin10D
  86. + 293393 * e12 / 251658240 * sin12D;
  87. }
  88. function calculateSigma(ellipticity, latitude) {
  89. if (ellipticity === 0.0) { // sphere
  90. return Math.log(Math.tan(0.5 * (_Math.CesiumMath.PI_OVER_TWO + latitude)));
  91. }
  92. var eSinL = ellipticity * Math.sin(latitude);
  93. return Math.log(Math.tan(0.5 * (_Math.CesiumMath.PI_OVER_TWO + latitude))) - (ellipticity / 2.0 * Math.log((1 + eSinL) / (1 - eSinL)));
  94. }
  95. function calculateHeading(ellipsoidRhumbLine, firstLongitude, firstLatitude, secondLongitude, secondLatitude) {
  96. var sigma1 = calculateSigma(ellipsoidRhumbLine._ellipticity, firstLatitude);
  97. var sigma2 = calculateSigma(ellipsoidRhumbLine._ellipticity, secondLatitude);
  98. return Math.atan2(_Math.CesiumMath.negativePiToPi(secondLongitude - firstLongitude), sigma2 - sigma1);
  99. }
  100. function calculateArcLength(ellipsoidRhumbLine, major, minor, firstLongitude, firstLatitude, secondLongitude, secondLatitude) {
  101. var heading = ellipsoidRhumbLine._heading;
  102. var deltaLongitude = secondLongitude - firstLongitude;
  103. var distance = 0.0;
  104. //Check to see if the rhumb line has constant latitude
  105. //This equation will diverge if heading gets close to 90 degrees
  106. if (_Math.CesiumMath.equalsEpsilon(Math.abs(heading), _Math.CesiumMath.PI_OVER_TWO, _Math.CesiumMath.EPSILON8)) { //If heading is close to 90 degrees
  107. if (major === minor) {
  108. distance = major * Math.cos(firstLatitude) * _Math.CesiumMath.negativePiToPi(deltaLongitude);
  109. } else {
  110. var sinPhi = Math.sin(firstLatitude);
  111. distance = major * Math.cos(firstLatitude) * _Math.CesiumMath.negativePiToPi(deltaLongitude) / Math.sqrt(1 - ellipsoidRhumbLine._ellipticitySquared * sinPhi * sinPhi);
  112. }
  113. } else {
  114. var M1 = calculateM(ellipsoidRhumbLine._ellipticity, major, firstLatitude);
  115. var M2 = calculateM(ellipsoidRhumbLine._ellipticity, major, secondLatitude);
  116. distance = (M2 - M1) / Math.cos(heading);
  117. }
  118. return Math.abs(distance);
  119. }
  120. var scratchCart1 = new Cartographic.Cartesian3();
  121. var scratchCart2 = new Cartographic.Cartesian3();
  122. function computeProperties(ellipsoidRhumbLine, start, end, ellipsoid) {
  123. var firstCartesian = Cartographic.Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1);
  124. var lastCartesian = Cartographic.Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2);
  125. //>>includeStart('debug', pragmas.debug);
  126. Check.Check.typeOf.number.greaterThanOrEquals('value', Math.abs(Math.abs(Cartographic.Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI), 0.0125);
  127. //>>includeEnd('debug');
  128. var major = ellipsoid.maximumRadius;
  129. var minor = ellipsoid.minimumRadius;
  130. var majorSquared = major * major;
  131. var minorSquared = minor * minor;
  132. ellipsoidRhumbLine._ellipticitySquared = (majorSquared - minorSquared) / majorSquared;
  133. ellipsoidRhumbLine._ellipticity = Math.sqrt(ellipsoidRhumbLine._ellipticitySquared);
  134. ellipsoidRhumbLine._start = Cartographic.Cartographic.clone(start, ellipsoidRhumbLine._start);
  135. ellipsoidRhumbLine._start.height = 0;
  136. ellipsoidRhumbLine._end = Cartographic.Cartographic.clone(end, ellipsoidRhumbLine._end);
  137. ellipsoidRhumbLine._end.height = 0;
  138. ellipsoidRhumbLine._heading = calculateHeading(ellipsoidRhumbLine, start.longitude, start.latitude, end.longitude, end.latitude);
  139. ellipsoidRhumbLine._distance = calculateArcLength(ellipsoidRhumbLine, ellipsoid.maximumRadius, ellipsoid.minimumRadius,
  140. start.longitude, start.latitude, end.longitude, end.latitude);
  141. }
  142. function interpolateUsingSurfaceDistance(start, heading, distance, major, ellipticity, result)
  143. {
  144. var ellipticitySquared = ellipticity * ellipticity;
  145. var longitude;
  146. var latitude;
  147. var deltaLongitude;
  148. //Check to see if the rhumb line has constant latitude
  149. //This won't converge if heading is close to 90 degrees
  150. if (Math.abs(_Math.CesiumMath.PI_OVER_TWO - Math.abs(heading)) > _Math.CesiumMath.EPSILON8) {
  151. //Calculate latitude of the second point
  152. var M1 = calculateM(ellipticity, major, start.latitude);
  153. var deltaM = distance * Math.cos(heading);
  154. var M2 = M1 + deltaM;
  155. latitude = calculateInverseM(M2, ellipticity, major);
  156. //Now find the longitude of the second point
  157. var sigma1 = calculateSigma(ellipticity, start.latitude);
  158. var sigma2 = calculateSigma(ellipticity, latitude);
  159. deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);
  160. longitude = _Math.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  161. } else { //If heading is close to 90 degrees
  162. latitude = start.latitude;
  163. var localRad;
  164. if (ellipticity === 0.0) { // sphere
  165. localRad = major * Math.cos(start.latitude);
  166. } else {
  167. var sinPhi = Math.sin(start.latitude);
  168. localRad = major * Math.cos(start.latitude) / Math.sqrt(1 - ellipticitySquared * sinPhi * sinPhi);
  169. }
  170. deltaLongitude = distance / localRad;
  171. if (heading > 0.0) {
  172. longitude = _Math.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  173. } else {
  174. longitude = _Math.CesiumMath.negativePiToPi(start.longitude - deltaLongitude);
  175. }
  176. }
  177. if (when.defined(result)) {
  178. result.longitude = longitude;
  179. result.latitude = latitude;
  180. result.height = 0;
  181. return result;
  182. }
  183. return new Cartographic.Cartographic(longitude, latitude, 0);
  184. }
  185. /**
  186. * Initializes a rhumb line on the ellipsoid connecting the two provided planetodetic points.
  187. *
  188. * @alias EllipsoidRhumbLine
  189. * @constructor
  190. *
  191. * @param {Cartographic} [start] The initial planetodetic point on the path.
  192. * @param {Cartographic} [end] The final planetodetic point on the path.
  193. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.
  194. *
  195. * @exception {DeveloperError} angle between start and end must be at least 0.0125 radians.
  196. */
  197. function EllipsoidRhumbLine(start, end, ellipsoid) {
  198. var e = when.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  199. this._ellipsoid = e;
  200. this._start = new Cartographic.Cartographic();
  201. this._end = new Cartographic.Cartographic();
  202. this._heading = undefined;
  203. this._distance = undefined;
  204. this._ellipticity = undefined;
  205. this._ellipticitySquared = undefined;
  206. if (when.defined(start) && when.defined(end)) {
  207. computeProperties(this, start, end, e);
  208. }
  209. }
  210. Object.defineProperties(EllipsoidRhumbLine.prototype, {
  211. /**
  212. * Gets the ellipsoid.
  213. * @memberof EllipsoidRhumbLine.prototype
  214. * @type {Ellipsoid}
  215. * @readonly
  216. */
  217. ellipsoid : {
  218. get : function() {
  219. return this._ellipsoid;
  220. }
  221. },
  222. /**
  223. * Gets the surface distance between the start and end point
  224. * @memberof EllipsoidRhumbLine.prototype
  225. * @type {Number}
  226. * @readonly
  227. */
  228. surfaceDistance : {
  229. get : function() {
  230. //>>includeStart('debug', pragmas.debug);
  231. Check.Check.defined('distance', this._distance);
  232. //>>includeEnd('debug');
  233. return this._distance;
  234. }
  235. },
  236. /**
  237. * Gets the initial planetodetic point on the path.
  238. * @memberof EllipsoidRhumbLine.prototype
  239. * @type {Cartographic}
  240. * @readonly
  241. */
  242. start : {
  243. get : function() {
  244. return this._start;
  245. }
  246. },
  247. /**
  248. * Gets the final planetodetic point on the path.
  249. * @memberof EllipsoidRhumbLine.prototype
  250. * @type {Cartographic}
  251. * @readonly
  252. */
  253. end : {
  254. get : function() {
  255. return this._end;
  256. }
  257. },
  258. /**
  259. * Gets the heading from the start point to the end point.
  260. * @memberof EllipsoidRhumbLine.prototype
  261. * @type {Number}
  262. * @readonly
  263. */
  264. heading : {
  265. get : function() {
  266. //>>includeStart('debug', pragmas.debug);
  267. Check.Check.defined('distance', this._distance);
  268. //>>includeEnd('debug');
  269. return this._heading;
  270. }
  271. }
  272. });
  273. /**
  274. * Create a rhumb line using an initial position with a heading and distance.
  275. *
  276. * @param {Cartographic} start The initial planetodetic point on the path.
  277. * @param {Number} heading The heading in radians.
  278. * @param {Number} distance The rhumb line distance between the start and end point.
  279. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.
  280. * @param {EllipsoidRhumbLine} [result] The object in which to store the result.
  281. * @returns {EllipsoidRhumbLine} The EllipsoidRhumbLine object.
  282. */
  283. EllipsoidRhumbLine.fromStartHeadingDistance = function(start, heading, distance, ellipsoid, result) {
  284. //>>includeStart('debug', pragmas.debug);
  285. Check.Check.defined('start', start);
  286. Check.Check.defined('heading', heading);
  287. Check.Check.defined('distance', distance);
  288. Check.Check.typeOf.number.greaterThan('distance', distance, 0.0);
  289. //>>includeEnd('debug');
  290. var e = when.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  291. var major = e.maximumRadius;
  292. var minor = e.minimumRadius;
  293. var majorSquared = major * major;
  294. var minorSquared = minor * minor;
  295. var ellipticity = Math.sqrt((majorSquared - minorSquared) / majorSquared);
  296. heading = _Math.CesiumMath.negativePiToPi(heading);
  297. var end = interpolateUsingSurfaceDistance(start, heading, distance, e.maximumRadius, ellipticity);
  298. if (!when.defined(result) || (when.defined(ellipsoid) && !ellipsoid.equals(result.ellipsoid))) {
  299. return new EllipsoidRhumbLine(start, end, e);
  300. }
  301. result.setEndPoints(start, end);
  302. return result;
  303. };
  304. /**
  305. * Sets the start and end points of the rhumb line.
  306. *
  307. * @param {Cartographic} start The initial planetodetic point on the path.
  308. * @param {Cartographic} end The final planetodetic point on the path.
  309. */
  310. EllipsoidRhumbLine.prototype.setEndPoints = function(start, end) {
  311. //>>includeStart('debug', pragmas.debug);
  312. Check.Check.defined('start', start);
  313. Check.Check.defined('end', end);
  314. //>>includeEnd('debug');
  315. computeProperties(this, start, end, this._ellipsoid);
  316. };
  317. /**
  318. * Provides the location of a point at the indicated portion along the rhumb line.
  319. *
  320. * @param {Number} fraction The portion of the distance between the initial and final points.
  321. * @param {Cartographic} [result] The object in which to store the result.
  322. * @returns {Cartographic} The location of the point along the rhumb line.
  323. */
  324. EllipsoidRhumbLine.prototype.interpolateUsingFraction = function(fraction, result) {
  325. return this.interpolateUsingSurfaceDistance(fraction * this._distance, result);
  326. };
  327. /**
  328. * Provides the location of a point at the indicated distance along the rhumb line.
  329. *
  330. * @param {Number} distance The distance from the inital point to the point of interest along the rhumbLine.
  331. * @param {Cartographic} [result] The object in which to store the result.
  332. * @returns {Cartographic} The location of the point along the rhumb line.
  333. *
  334. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  335. */
  336. EllipsoidRhumbLine.prototype.interpolateUsingSurfaceDistance = function(distance, result) {
  337. //>>includeStart('debug', pragmas.debug);
  338. Check.Check.typeOf.number('distance', distance);
  339. if (!when.defined(this._distance) || this._distance === 0.0) {
  340. throw new Check.DeveloperError('EllipsoidRhumbLine must have distinct start and end set.');
  341. }
  342. //>>includeEnd('debug');
  343. return interpolateUsingSurfaceDistance(this._start, this._heading, distance, this._ellipsoid.maximumRadius, this._ellipticity, result);
  344. };
  345. /**
  346. * Provides the location of a point at the indicated longitude along the rhumb line.
  347. * 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.
  348. *
  349. * @param {Number} intersectionLongitude The longitude, in radians, at which to find the intersection point from the starting point using the heading.
  350. * @param {Cartographic} [result] The object in which to store the result.
  351. * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.
  352. *
  353. * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.
  354. */
  355. EllipsoidRhumbLine.prototype.findIntersectionWithLongitude = function(intersectionLongitude, result) {
  356. //>>includeStart('debug', pragmas.debug);
  357. Check.Check.typeOf.number('intersectionLongitude', intersectionLongitude);
  358. if (!when.defined(this._distance) || this._distance === 0.0) {
  359. throw new Check.DeveloperError('EllipsoidRhumbLine must have distinct start and end set.');
  360. }
  361. //>>includeEnd('debug');
  362. var ellipticity = this._ellipticity;
  363. var heading = this._heading;
  364. var absHeading = Math.abs(heading);
  365. var start = this._start;
  366. intersectionLongitude = _Math.CesiumMath.negativePiToPi(intersectionLongitude);
  367. if (_Math.CesiumMath.equalsEpsilon(Math.abs(intersectionLongitude), Math.PI, _Math.CesiumMath.EPSILON14)) {
  368. intersectionLongitude = _Math.CesiumMath.sign(start.longitude) * Math.PI;
  369. }
  370. if (!when.defined(result)) {
  371. result = new Cartographic.Cartographic();
  372. }
  373. // If heading is -PI/2 or PI/2, this is an E-W rhumb line
  374. // If heading is 0 or PI, this is an N-S rhumb line
  375. if (Math.abs(_Math.CesiumMath.PI_OVER_TWO - absHeading) <= _Math.CesiumMath.EPSILON8) {
  376. result.longitude = intersectionLongitude;
  377. result.latitude = start.latitude;
  378. result.height = 0;
  379. return result;
  380. } else if (_Math.CesiumMath.equalsEpsilon(Math.abs(_Math.CesiumMath.PI_OVER_TWO - absHeading), _Math.CesiumMath.PI_OVER_TWO, _Math.CesiumMath.EPSILON8)) {
  381. if (_Math.CesiumMath.equalsEpsilon(intersectionLongitude, start.longitude, _Math.CesiumMath.EPSILON12)) {
  382. return undefined;
  383. }
  384. result.longitude = intersectionLongitude;
  385. result.latitude = _Math.CesiumMath.PI_OVER_TWO * _Math.CesiumMath.sign(_Math.CesiumMath.PI_OVER_TWO - heading);
  386. result.height = 0;
  387. return result;
  388. }
  389. // Use iterative solver from Equation 9 from http://edwilliams.org/ellipsoid/ellipsoid.pdf
  390. var phi1 = start.latitude;
  391. var eSinPhi1 = ellipticity * Math.sin(phi1);
  392. var leftComponent = Math.tan(0.5 * (_Math.CesiumMath.PI_OVER_TWO + phi1)) * Math.exp((intersectionLongitude - start.longitude) / Math.tan(heading));
  393. var denominator = (1 + eSinPhi1) / (1 - eSinPhi1);
  394. var newPhi = start.latitude;
  395. var phi;
  396. do {
  397. phi = newPhi;
  398. var eSinPhi = ellipticity * Math.sin(phi);
  399. var numerator = (1 + eSinPhi) / (1 - eSinPhi);
  400. newPhi = 2 * Math.atan(leftComponent * Math.pow(numerator / denominator, ellipticity / 2)) - _Math.CesiumMath.PI_OVER_TWO;
  401. } while (!_Math.CesiumMath.equalsEpsilon(newPhi, phi, _Math.CesiumMath.EPSILON12));
  402. result.longitude = intersectionLongitude;
  403. result.latitude = newPhi;
  404. result.height = 0;
  405. return result;
  406. };
  407. /**
  408. * Provides the location of a point at the indicated latitude along the rhumb line.
  409. * 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.
  410. *
  411. * @param {Number} intersectionLatitude The latitude, in radians, at which to find the intersection point from the starting point using the heading.
  412. * @param {Cartographic} [result] The object in which to store the result.
  413. * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.
  414. *
  415. * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.
  416. */
  417. EllipsoidRhumbLine.prototype.findIntersectionWithLatitude = function(intersectionLatitude, result) {
  418. //>>includeStart('debug', pragmas.debug);
  419. Check.Check.typeOf.number('intersectionLatitude', intersectionLatitude);
  420. if (!when.defined(this._distance) || this._distance === 0.0) {
  421. throw new Check.DeveloperError('EllipsoidRhumbLine must have distinct start and end set.');
  422. }
  423. //>>includeEnd('debug');
  424. var ellipticity = this._ellipticity;
  425. var heading = this._heading;
  426. var start = this._start;
  427. // If start and end have same latitude, return undefined since it's either no intersection or infinite intersections
  428. if (_Math.CesiumMath.equalsEpsilon(Math.abs(heading), _Math.CesiumMath.PI_OVER_TWO, _Math.CesiumMath.EPSILON8)) {
  429. return;
  430. }
  431. // Can be solved using the same equations from interpolateUsingSurfaceDistance
  432. var sigma1 = calculateSigma(ellipticity, start.latitude);
  433. var sigma2 = calculateSigma(ellipticity, intersectionLatitude);
  434. var deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);
  435. var longitude = _Math.CesiumMath.negativePiToPi(start.longitude + deltaLongitude);
  436. if (when.defined(result)) {
  437. result.longitude = longitude;
  438. result.latitude = intersectionLatitude;
  439. result.height = 0;
  440. return result;
  441. }
  442. return new Cartographic.Cartographic(longitude, intersectionLatitude, 0);
  443. };
  444. exports.EllipsoidRhumbLine = EllipsoidRhumbLine;
  445. });