EllipsoidGeodesic-53e988a6.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 setConstants(ellipsoidGeodesic) {
  4. var uSquared = ellipsoidGeodesic._uSquared;
  5. var a = ellipsoidGeodesic._ellipsoid.maximumRadius;
  6. var b = ellipsoidGeodesic._ellipsoid.minimumRadius;
  7. var f = (a - b) / a;
  8. var cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);
  9. var sineHeading = Math.sin(ellipsoidGeodesic._startHeading);
  10. var tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);
  11. var cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);
  12. var sineU = cosineU * tanU;
  13. var sigma = Math.atan2(tanU, cosineHeading);
  14. var sineAlpha = cosineU * sineHeading;
  15. var sineSquaredAlpha = sineAlpha * sineAlpha;
  16. var cosineSquaredAlpha = 1.0 - sineSquaredAlpha;
  17. var cosineAlpha = Math.sqrt(cosineSquaredAlpha);
  18. var u2Over4 = uSquared / 4.0;
  19. var u4Over16 = u2Over4 * u2Over4;
  20. var u6Over64 = u4Over16 * u2Over4;
  21. var u8Over256 = u4Over16 * u4Over16;
  22. var a0 = (1.0 + u2Over4 - 3.0 * u4Over16 / 4.0 + 5.0 * u6Over64 / 4.0 - 175.0 * u8Over256 / 64.0);
  23. var a1 = (1.0 - u2Over4 + 15.0 * u4Over16 / 8.0 - 35.0 * u6Over64 / 8.0);
  24. var a2 = (1.0 - 3.0 * u2Over4 + 35.0 * u4Over16 / 4.0);
  25. var a3 = (1.0 - 5.0 * u2Over4);
  26. var distanceRatio = a0 * sigma - a1 * Math.sin(2.0 * sigma) * u2Over4 / 2.0 - a2 * Math.sin(4.0 * sigma) * u4Over16 / 16.0 -
  27. a3 * Math.sin(6.0 * sigma) * u6Over64 / 48.0 - Math.sin(8.0 * sigma) * 5.0 * u8Over256 / 512;
  28. var constants = ellipsoidGeodesic._constants;
  29. constants.a = a;
  30. constants.b = b;
  31. constants.f = f;
  32. constants.cosineHeading = cosineHeading;
  33. constants.sineHeading = sineHeading;
  34. constants.tanU = tanU;
  35. constants.cosineU = cosineU;
  36. constants.sineU = sineU;
  37. constants.sigma = sigma;
  38. constants.sineAlpha = sineAlpha;
  39. constants.sineSquaredAlpha = sineSquaredAlpha;
  40. constants.cosineSquaredAlpha = cosineSquaredAlpha;
  41. constants.cosineAlpha = cosineAlpha;
  42. constants.u2Over4 = u2Over4;
  43. constants.u4Over16 = u4Over16;
  44. constants.u6Over64 = u6Over64;
  45. constants.u8Over256 = u8Over256;
  46. constants.a0 = a0;
  47. constants.a1 = a1;
  48. constants.a2 = a2;
  49. constants.a3 = a3;
  50. constants.distanceRatio = distanceRatio;
  51. }
  52. function computeC(f, cosineSquaredAlpha) {
  53. return f * cosineSquaredAlpha * (4.0 + f * (4.0 - 3.0 * cosineSquaredAlpha)) / 16.0;
  54. }
  55. function computeDeltaLambda(f, sineAlpha, cosineSquaredAlpha, sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint) {
  56. var C = computeC(f, cosineSquaredAlpha);
  57. return (1.0 - C) * f * sineAlpha * (sigma + C * sineSigma * (cosineTwiceSigmaMidpoint +
  58. C * cosineSigma * (2.0 * cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint - 1.0)));
  59. }
  60. function vincentyInverseFormula(ellipsoidGeodesic, major, minor, firstLongitude, firstLatitude, secondLongitude, secondLatitude) {
  61. var eff = (major - minor) / major;
  62. var l = secondLongitude - firstLongitude;
  63. var u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));
  64. var u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));
  65. var cosineU1 = Math.cos(u1);
  66. var sineU1 = Math.sin(u1);
  67. var cosineU2 = Math.cos(u2);
  68. var sineU2 = Math.sin(u2);
  69. var cc = cosineU1 * cosineU2;
  70. var cs = cosineU1 * sineU2;
  71. var ss = sineU1 * sineU2;
  72. var sc = sineU1 * cosineU2;
  73. var lambda = l;
  74. var lambdaDot = _Math.CesiumMath.TWO_PI;
  75. var cosineLambda = Math.cos(lambda);
  76. var sineLambda = Math.sin(lambda);
  77. var sigma;
  78. var cosineSigma;
  79. var sineSigma;
  80. var cosineSquaredAlpha;
  81. var cosineTwiceSigmaMidpoint;
  82. do {
  83. cosineLambda = Math.cos(lambda);
  84. sineLambda = Math.sin(lambda);
  85. var temp = cs - sc * cosineLambda;
  86. sineSigma = Math.sqrt(cosineU2 * cosineU2 * sineLambda * sineLambda + temp * temp);
  87. cosineSigma = ss + cc * cosineLambda;
  88. sigma = Math.atan2(sineSigma, cosineSigma);
  89. var sineAlpha;
  90. if (sineSigma === 0.0) {
  91. sineAlpha = 0.0;
  92. cosineSquaredAlpha = 1.0;
  93. } else {
  94. sineAlpha = cc * sineLambda / sineSigma;
  95. cosineSquaredAlpha = 1.0 - sineAlpha * sineAlpha;
  96. }
  97. lambdaDot = lambda;
  98. cosineTwiceSigmaMidpoint = cosineSigma - 2.0 * ss / cosineSquaredAlpha;
  99. if (isNaN(cosineTwiceSigmaMidpoint)) {
  100. cosineTwiceSigmaMidpoint = 0.0;
  101. }
  102. lambda = l + computeDeltaLambda(eff, sineAlpha, cosineSquaredAlpha,
  103. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  104. } while (Math.abs(lambda - lambdaDot) > _Math.CesiumMath.EPSILON12);
  105. var uSquared = cosineSquaredAlpha * (major * major - minor * minor) / (minor * minor);
  106. var A = 1.0 + uSquared * (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0)) / 16384.0;
  107. var B = uSquared * (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0)) / 1024.0;
  108. var cosineSquaredTwiceSigmaMidpoint = cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;
  109. var deltaSigma = B * sineSigma * (cosineTwiceSigmaMidpoint + B * (cosineSigma *
  110. (2.0 * cosineSquaredTwiceSigmaMidpoint - 1.0) - B * cosineTwiceSigmaMidpoint *
  111. (4.0 * sineSigma * sineSigma - 3.0) * (4.0 * cosineSquaredTwiceSigmaMidpoint - 3.0) / 6.0) / 4.0);
  112. var distance = minor * A * (sigma - deltaSigma);
  113. var startHeading = Math.atan2(cosineU2 * sineLambda, cs - sc * cosineLambda);
  114. var endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);
  115. ellipsoidGeodesic._distance = distance;
  116. ellipsoidGeodesic._startHeading = startHeading;
  117. ellipsoidGeodesic._endHeading = endHeading;
  118. ellipsoidGeodesic._uSquared = uSquared;
  119. }
  120. var scratchCart1 = new Cartesian2.Cartesian3();
  121. var scratchCart2 = new Cartesian2.Cartesian3();
  122. function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
  123. var firstCartesian = Cartesian2.Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1);
  124. var lastCartesian = Cartesian2.Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2);
  125. //>>includeStart('debug', pragmas.debug);
  126. Check.Check.typeOf.number.greaterThanOrEquals('value', Math.abs(Math.abs(Cartesian2.Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI), 0.0125);
  127. //>>includeEnd('debug');
  128. vincentyInverseFormula(ellipsoidGeodesic, ellipsoid.maximumRadius, ellipsoid.minimumRadius,
  129. start.longitude, start.latitude, end.longitude, end.latitude);
  130. ellipsoidGeodesic._start = Cartesian2.Cartographic.clone(start, ellipsoidGeodesic._start);
  131. ellipsoidGeodesic._end = Cartesian2.Cartographic.clone(end, ellipsoidGeodesic._end);
  132. ellipsoidGeodesic._start.height = 0;
  133. ellipsoidGeodesic._end.height = 0;
  134. setConstants(ellipsoidGeodesic);
  135. }
  136. /**
  137. * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.
  138. *
  139. * @alias EllipsoidGeodesic
  140. * @constructor
  141. *
  142. * @param {Cartographic} [start] The initial planetodetic point on the path.
  143. * @param {Cartographic} [end] The final planetodetic point on the path.
  144. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.
  145. */
  146. function EllipsoidGeodesic(start, end, ellipsoid) {
  147. var e = defaultValue.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  148. this._ellipsoid = e;
  149. this._start = new Cartesian2.Cartographic();
  150. this._end = new Cartesian2.Cartographic();
  151. this._constants = {};
  152. this._startHeading = undefined;
  153. this._endHeading = undefined;
  154. this._distance = undefined;
  155. this._uSquared = undefined;
  156. if (defined.defined(start) && defined.defined(end)) {
  157. computeProperties(this, start, end, e);
  158. }
  159. }
  160. defineProperties.defineProperties(EllipsoidGeodesic.prototype, {
  161. /**
  162. * Gets the ellipsoid.
  163. * @memberof EllipsoidGeodesic.prototype
  164. * @type {Ellipsoid}
  165. * @readonly
  166. */
  167. ellipsoid : {
  168. get : function() {
  169. return this._ellipsoid;
  170. }
  171. },
  172. /**
  173. * Gets the surface distance between the start and end point
  174. * @memberof EllipsoidGeodesic.prototype
  175. * @type {Number}
  176. * @readonly
  177. */
  178. surfaceDistance : {
  179. get : function() {
  180. //>>includeStart('debug', pragmas.debug);
  181. Check.Check.defined('distance', this._distance);
  182. //>>includeEnd('debug');
  183. return this._distance;
  184. }
  185. },
  186. /**
  187. * Gets the initial planetodetic point on the path.
  188. * @memberof EllipsoidGeodesic.prototype
  189. * @type {Cartographic}
  190. * @readonly
  191. */
  192. start : {
  193. get : function() {
  194. return this._start;
  195. }
  196. },
  197. /**
  198. * Gets the final planetodetic point on the path.
  199. * @memberof EllipsoidGeodesic.prototype
  200. * @type {Cartographic}
  201. * @readonly
  202. */
  203. end : {
  204. get : function() {
  205. return this._end;
  206. }
  207. },
  208. /**
  209. * Gets the heading at the initial point.
  210. * @memberof EllipsoidGeodesic.prototype
  211. * @type {Number}
  212. * @readonly
  213. */
  214. startHeading : {
  215. get : function() {
  216. //>>includeStart('debug', pragmas.debug);
  217. Check.Check.defined('distance', this._distance);
  218. //>>includeEnd('debug');
  219. return this._startHeading;
  220. }
  221. },
  222. /**
  223. * Gets the heading at the final point.
  224. * @memberof EllipsoidGeodesic.prototype
  225. * @type {Number}
  226. * @readonly
  227. */
  228. endHeading : {
  229. get : function() {
  230. //>>includeStart('debug', pragmas.debug);
  231. Check.Check.defined('distance', this._distance);
  232. //>>includeEnd('debug');
  233. return this._endHeading;
  234. }
  235. }
  236. });
  237. /**
  238. * Sets the start and end points of the geodesic
  239. *
  240. * @param {Cartographic} start The initial planetodetic point on the path.
  241. * @param {Cartographic} end The final planetodetic point on the path.
  242. */
  243. EllipsoidGeodesic.prototype.setEndPoints = function(start, end) {
  244. //>>includeStart('debug', pragmas.debug);
  245. Check.Check.defined('start', start);
  246. Check.Check.defined('end', end);
  247. //>>includeEnd('debug');
  248. computeProperties(this, start, end, this._ellipsoid);
  249. };
  250. /**
  251. * Provides the location of a point at the indicated portion along the geodesic.
  252. *
  253. * @param {Number} fraction The portion of the distance between the initial and final points.
  254. * @param {Cartographic} result The object in which to store the result.
  255. * @returns {Cartographic} The location of the point along the geodesic.
  256. */
  257. EllipsoidGeodesic.prototype.interpolateUsingFraction = function(fraction, result) {
  258. return this.interpolateUsingSurfaceDistance(this._distance * fraction, result);
  259. };
  260. /**
  261. * Provides the location of a point at the indicated distance along the geodesic.
  262. *
  263. * @param {Number} distance The distance from the inital point to the point of interest along the geodesic
  264. * @param {Cartographic} result The object in which to store the result.
  265. * @returns {Cartographic} The location of the point along the geodesic.
  266. *
  267. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  268. */
  269. EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function(distance, result) {
  270. //>>includeStart('debug', pragmas.debug);
  271. Check.Check.defined('distance', this._distance);
  272. //>>includeEnd('debug');
  273. var constants = this._constants;
  274. var s = constants.distanceRatio + distance / constants.b;
  275. var cosine2S = Math.cos(2.0 * s);
  276. var cosine4S = Math.cos(4.0 * s);
  277. var cosine6S = Math.cos(6.0 * s);
  278. var sine2S = Math.sin(2.0 * s);
  279. var sine4S = Math.sin(4.0 * s);
  280. var sine6S = Math.sin(6.0 * s);
  281. var sine8S = Math.sin(8.0 * s);
  282. var s2 = s * s;
  283. var s3 = s * s2;
  284. var u8Over256 = constants.u8Over256;
  285. var u2Over4 = constants.u2Over4;
  286. var u6Over64 = constants.u6Over64;
  287. var u4Over16 = constants.u4Over16;
  288. var sigma = 2.0 * s3 * u8Over256 * cosine2S / 3.0 +
  289. s * (1.0 - u2Over4 + 7.0 * u4Over16 / 4.0 - 15.0 * u6Over64 / 4.0 + 579.0 * u8Over256 / 64.0 -
  290. (u4Over16 - 15.0 * u6Over64 / 4.0 + 187.0 * u8Over256 / 16.0) * cosine2S -
  291. (5.0 * u6Over64 / 4.0 - 115.0 * u8Over256 / 16.0) * cosine4S -
  292. 29.0 * u8Over256 * cosine6S / 16.0) +
  293. (u2Over4 / 2.0 - u4Over16 + 71.0 * u6Over64 / 32.0 - 85.0 * u8Over256 / 16.0) * sine2S +
  294. (5.0 * u4Over16 / 16.0 - 5.0 * u6Over64 / 4.0 + 383.0 * u8Over256 / 96.0) * sine4S -
  295. s2 * ((u6Over64 - 11.0 * u8Over256 / 2.0) * sine2S + 5.0 * u8Over256 * sine4S / 2.0) +
  296. (29.0 * u6Over64 / 96.0 - 29.0 * u8Over256 / 16.0) * sine6S +
  297. 539.0 * u8Over256 * sine8S / 1536.0;
  298. var theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);
  299. var latitude = Math.atan(constants.a / constants.b * Math.tan(theta));
  300. // Redefine in terms of relative argument of latitude.
  301. sigma = sigma - constants.sigma;
  302. var cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);
  303. var sineSigma = Math.sin(sigma);
  304. var cosineSigma = Math.cos(sigma);
  305. var cc = constants.cosineU * cosineSigma;
  306. var ss = constants.sineU * sineSigma;
  307. var lambda = Math.atan2(sineSigma * constants.sineHeading, cc - ss * constants.cosineHeading);
  308. var l = lambda - computeDeltaLambda(constants.f, constants.sineAlpha, constants.cosineSquaredAlpha,
  309. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  310. if (defined.defined(result)) {
  311. result.longitude = this._start.longitude + l;
  312. result.latitude = latitude;
  313. result.height = 0.0;
  314. return result;
  315. }
  316. return new Cartesian2.Cartographic(this._start.longitude + l, latitude, 0.0);
  317. };
  318. exports.EllipsoidGeodesic = EllipsoidGeodesic;
  319. });