EllipsoidRhumbLine.js 22 KB

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