EllipsoidRhumbLine-c6cdbfd3.js 24 KB

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