EllipseGeometryLibrary-5e06d338.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './Math-392d0035', './Cartesian2-a5d6dde9', './Transforms-81680c41'], function (exports, _Math, Cartesian2, Transforms) { 'use strict';
  3. var EllipseGeometryLibrary = {};
  4. var rotAxis = new Cartesian2.Cartesian3();
  5. var tempVec = new Cartesian2.Cartesian3();
  6. var unitQuat = new Transforms.Quaternion();
  7. var rotMtx = new Transforms.Matrix3();
  8. function pointOnEllipsoid(
  9. theta,
  10. rotation,
  11. northVec,
  12. eastVec,
  13. aSqr,
  14. ab,
  15. bSqr,
  16. mag,
  17. unitPos,
  18. result
  19. ) {
  20. var azimuth = theta + rotation;
  21. Cartesian2.Cartesian3.multiplyByScalar(eastVec, Math.cos(azimuth), rotAxis);
  22. Cartesian2.Cartesian3.multiplyByScalar(northVec, Math.sin(azimuth), tempVec);
  23. Cartesian2.Cartesian3.add(rotAxis, tempVec, rotAxis);
  24. var cosThetaSquared = Math.cos(theta);
  25. cosThetaSquared = cosThetaSquared * cosThetaSquared;
  26. var sinThetaSquared = Math.sin(theta);
  27. sinThetaSquared = sinThetaSquared * sinThetaSquared;
  28. var radius = ab / Math.sqrt(bSqr * cosThetaSquared + aSqr * sinThetaSquared);
  29. var angle = radius / mag;
  30. // Create the quaternion to rotate the position vector to the boundary of the ellipse.
  31. Transforms.Quaternion.fromAxisAngle(rotAxis, angle, unitQuat);
  32. Transforms.Matrix3.fromQuaternion(unitQuat, rotMtx);
  33. Transforms.Matrix3.multiplyByVector(rotMtx, unitPos, result);
  34. Cartesian2.Cartesian3.normalize(result, result);
  35. Cartesian2.Cartesian3.multiplyByScalar(result, mag, result);
  36. return result;
  37. }
  38. var scratchCartesian1 = new Cartesian2.Cartesian3();
  39. var scratchCartesian2 = new Cartesian2.Cartesian3();
  40. var scratchCartesian3 = new Cartesian2.Cartesian3();
  41. var scratchNormal = new Cartesian2.Cartesian3();
  42. /**
  43. * Returns the positions raised to the given heights
  44. * @private
  45. */
  46. EllipseGeometryLibrary.raisePositionsToHeight = function (
  47. positions,
  48. options,
  49. extrude
  50. ) {
  51. var ellipsoid = options.ellipsoid;
  52. var height = options.height;
  53. var extrudedHeight = options.extrudedHeight;
  54. var size = extrude ? (positions.length / 3) * 2 : positions.length / 3;
  55. var finalPositions = new Float64Array(size * 3);
  56. var length = positions.length;
  57. var bottomOffset = extrude ? length : 0;
  58. for (var i = 0; i < length; i += 3) {
  59. var i1 = i + 1;
  60. var i2 = i + 2;
  61. var position = Cartesian2.Cartesian3.fromArray(positions, i, scratchCartesian1);
  62. ellipsoid.scaleToGeodeticSurface(position, position);
  63. var extrudedPosition = Cartesian2.Cartesian3.clone(position, scratchCartesian2);
  64. var normal = ellipsoid.geodeticSurfaceNormal(position, scratchNormal);
  65. var scaledNormal = Cartesian2.Cartesian3.multiplyByScalar(
  66. normal,
  67. height,
  68. scratchCartesian3
  69. );
  70. Cartesian2.Cartesian3.add(position, scaledNormal, position);
  71. if (extrude) {
  72. Cartesian2.Cartesian3.multiplyByScalar(normal, extrudedHeight, scaledNormal);
  73. Cartesian2.Cartesian3.add(extrudedPosition, scaledNormal, extrudedPosition);
  74. finalPositions[i + bottomOffset] = extrudedPosition.x;
  75. finalPositions[i1 + bottomOffset] = extrudedPosition.y;
  76. finalPositions[i2 + bottomOffset] = extrudedPosition.z;
  77. }
  78. finalPositions[i] = position.x;
  79. finalPositions[i1] = position.y;
  80. finalPositions[i2] = position.z;
  81. }
  82. return finalPositions;
  83. };
  84. var unitPosScratch = new Cartesian2.Cartesian3();
  85. var eastVecScratch = new Cartesian2.Cartesian3();
  86. var northVecScratch = new Cartesian2.Cartesian3();
  87. /**
  88. * Returns an array of positions that make up the ellipse.
  89. * @private
  90. */
  91. EllipseGeometryLibrary.computeEllipsePositions = function (
  92. options,
  93. addFillPositions,
  94. addEdgePositions
  95. ) {
  96. var semiMinorAxis = options.semiMinorAxis;
  97. var semiMajorAxis = options.semiMajorAxis;
  98. var rotation = options.rotation;
  99. var center = options.center;
  100. // Computing the arc-length of the ellipse is too expensive to be practical. Estimating it using the
  101. // arc length of the sphere is too inaccurate and creates sharp edges when either the semi-major or
  102. // semi-minor axis is much bigger than the other. Instead, scale the angle delta to make
  103. // the distance along the ellipse boundary more closely match the granularity.
  104. var granularity = options.granularity * 8.0;
  105. var aSqr = semiMinorAxis * semiMinorAxis;
  106. var bSqr = semiMajorAxis * semiMajorAxis;
  107. var ab = semiMajorAxis * semiMinorAxis;
  108. var mag = Cartesian2.Cartesian3.magnitude(center);
  109. var unitPos = Cartesian2.Cartesian3.normalize(center, unitPosScratch);
  110. var eastVec = Cartesian2.Cartesian3.cross(Cartesian2.Cartesian3.UNIT_Z, center, eastVecScratch);
  111. eastVec = Cartesian2.Cartesian3.normalize(eastVec, eastVec);
  112. var northVec = Cartesian2.Cartesian3.cross(unitPos, eastVec, northVecScratch);
  113. // The number of points in the first quadrant
  114. var numPts = 1 + Math.ceil(_Math.CesiumMath.PI_OVER_TWO / granularity);
  115. var deltaTheta = _Math.CesiumMath.PI_OVER_TWO / (numPts - 1);
  116. var theta = _Math.CesiumMath.PI_OVER_TWO - numPts * deltaTheta;
  117. if (theta < 0.0) {
  118. numPts -= Math.ceil(Math.abs(theta) / deltaTheta);
  119. }
  120. // If the number of points were three, the ellipse
  121. // would be tessellated like below:
  122. //
  123. // *---*
  124. // / | \ | \
  125. // *---*---*---*
  126. // / | \ | \ | \ | \
  127. // / .*---*---*---*. \
  128. // * ` | \ | \ | \ | `*
  129. // \`.*---*---*---*.`/
  130. // \ | \ | \ | \ | /
  131. // *---*---*---*
  132. // \ | \ | /
  133. // *---*
  134. // The first and last column have one position and fan to connect to the adjacent column.
  135. // Each other vertical column contains an even number of positions.
  136. var size = 2 * (numPts * (numPts + 2));
  137. var positions = addFillPositions ? new Array(size * 3) : undefined;
  138. var positionIndex = 0;
  139. var position = scratchCartesian1;
  140. var reflectedPosition = scratchCartesian2;
  141. var outerPositionsLength = numPts * 4 * 3;
  142. var outerRightIndex = outerPositionsLength - 1;
  143. var outerLeftIndex = 0;
  144. var outerPositions = addEdgePositions
  145. ? new Array(outerPositionsLength)
  146. : undefined;
  147. var i;
  148. var j;
  149. var numInterior;
  150. var t;
  151. var interiorPosition;
  152. // Compute points in the 'eastern' half of the ellipse
  153. theta = _Math.CesiumMath.PI_OVER_TWO;
  154. position = pointOnEllipsoid(
  155. theta,
  156. rotation,
  157. northVec,
  158. eastVec,
  159. aSqr,
  160. ab,
  161. bSqr,
  162. mag,
  163. unitPos,
  164. position
  165. );
  166. if (addFillPositions) {
  167. positions[positionIndex++] = position.x;
  168. positions[positionIndex++] = position.y;
  169. positions[positionIndex++] = position.z;
  170. }
  171. if (addEdgePositions) {
  172. outerPositions[outerRightIndex--] = position.z;
  173. outerPositions[outerRightIndex--] = position.y;
  174. outerPositions[outerRightIndex--] = position.x;
  175. }
  176. theta = _Math.CesiumMath.PI_OVER_TWO - deltaTheta;
  177. for (i = 1; i < numPts + 1; ++i) {
  178. position = pointOnEllipsoid(
  179. theta,
  180. rotation,
  181. northVec,
  182. eastVec,
  183. aSqr,
  184. ab,
  185. bSqr,
  186. mag,
  187. unitPos,
  188. position
  189. );
  190. reflectedPosition = pointOnEllipsoid(
  191. Math.PI - theta,
  192. rotation,
  193. northVec,
  194. eastVec,
  195. aSqr,
  196. ab,
  197. bSqr,
  198. mag,
  199. unitPos,
  200. reflectedPosition
  201. );
  202. if (addFillPositions) {
  203. positions[positionIndex++] = position.x;
  204. positions[positionIndex++] = position.y;
  205. positions[positionIndex++] = position.z;
  206. numInterior = 2 * i + 2;
  207. for (j = 1; j < numInterior - 1; ++j) {
  208. t = j / (numInterior - 1);
  209. interiorPosition = Cartesian2.Cartesian3.lerp(
  210. position,
  211. reflectedPosition,
  212. t,
  213. scratchCartesian3
  214. );
  215. positions[positionIndex++] = interiorPosition.x;
  216. positions[positionIndex++] = interiorPosition.y;
  217. positions[positionIndex++] = interiorPosition.z;
  218. }
  219. positions[positionIndex++] = reflectedPosition.x;
  220. positions[positionIndex++] = reflectedPosition.y;
  221. positions[positionIndex++] = reflectedPosition.z;
  222. }
  223. if (addEdgePositions) {
  224. outerPositions[outerRightIndex--] = position.z;
  225. outerPositions[outerRightIndex--] = position.y;
  226. outerPositions[outerRightIndex--] = position.x;
  227. outerPositions[outerLeftIndex++] = reflectedPosition.x;
  228. outerPositions[outerLeftIndex++] = reflectedPosition.y;
  229. outerPositions[outerLeftIndex++] = reflectedPosition.z;
  230. }
  231. theta = _Math.CesiumMath.PI_OVER_TWO - (i + 1) * deltaTheta;
  232. }
  233. // Compute points in the 'western' half of the ellipse
  234. for (i = numPts; i > 1; --i) {
  235. theta = _Math.CesiumMath.PI_OVER_TWO - (i - 1) * deltaTheta;
  236. position = pointOnEllipsoid(
  237. -theta,
  238. rotation,
  239. northVec,
  240. eastVec,
  241. aSqr,
  242. ab,
  243. bSqr,
  244. mag,
  245. unitPos,
  246. position
  247. );
  248. reflectedPosition = pointOnEllipsoid(
  249. theta + Math.PI,
  250. rotation,
  251. northVec,
  252. eastVec,
  253. aSqr,
  254. ab,
  255. bSqr,
  256. mag,
  257. unitPos,
  258. reflectedPosition
  259. );
  260. if (addFillPositions) {
  261. positions[positionIndex++] = position.x;
  262. positions[positionIndex++] = position.y;
  263. positions[positionIndex++] = position.z;
  264. numInterior = 2 * (i - 1) + 2;
  265. for (j = 1; j < numInterior - 1; ++j) {
  266. t = j / (numInterior - 1);
  267. interiorPosition = Cartesian2.Cartesian3.lerp(
  268. position,
  269. reflectedPosition,
  270. t,
  271. scratchCartesian3
  272. );
  273. positions[positionIndex++] = interiorPosition.x;
  274. positions[positionIndex++] = interiorPosition.y;
  275. positions[positionIndex++] = interiorPosition.z;
  276. }
  277. positions[positionIndex++] = reflectedPosition.x;
  278. positions[positionIndex++] = reflectedPosition.y;
  279. positions[positionIndex++] = reflectedPosition.z;
  280. }
  281. if (addEdgePositions) {
  282. outerPositions[outerRightIndex--] = position.z;
  283. outerPositions[outerRightIndex--] = position.y;
  284. outerPositions[outerRightIndex--] = position.x;
  285. outerPositions[outerLeftIndex++] = reflectedPosition.x;
  286. outerPositions[outerLeftIndex++] = reflectedPosition.y;
  287. outerPositions[outerLeftIndex++] = reflectedPosition.z;
  288. }
  289. }
  290. theta = _Math.CesiumMath.PI_OVER_TWO;
  291. position = pointOnEllipsoid(
  292. -theta,
  293. rotation,
  294. northVec,
  295. eastVec,
  296. aSqr,
  297. ab,
  298. bSqr,
  299. mag,
  300. unitPos,
  301. position
  302. );
  303. var r = {};
  304. if (addFillPositions) {
  305. positions[positionIndex++] = position.x;
  306. positions[positionIndex++] = position.y;
  307. positions[positionIndex++] = position.z;
  308. r.positions = positions;
  309. r.numPts = numPts;
  310. }
  311. if (addEdgePositions) {
  312. outerPositions[outerRightIndex--] = position.z;
  313. outerPositions[outerRightIndex--] = position.y;
  314. outerPositions[outerRightIndex--] = position.x;
  315. r.outerPositions = outerPositions;
  316. }
  317. return r;
  318. };
  319. exports.EllipseGeometryLibrary = EllipseGeometryLibrary;
  320. });