EllipsoidTangentPlane-1e8d1fc2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './AxisAlignedBoundingBox-df2331b2', './Matrix2-69c32d33', './RuntimeError-c581ca93', './defaultValue-94c3e563', './IntersectionTests-d5d945ac', './Plane-069b6800', './Transforms-323408fe'], (function (exports, AxisAlignedBoundingBox, Matrix2, RuntimeError, defaultValue, IntersectionTests, Plane, Transforms) { 'use strict';
  3. const scratchCart4 = new Matrix2.Cartesian4();
  4. /**
  5. * A plane tangent to the provided ellipsoid at the provided origin.
  6. * If origin is not on the surface of the ellipsoid, it's surface projection will be used.
  7. * If origin is at the center of the ellipsoid, an exception will be thrown.
  8. * @alias EllipsoidTangentPlane
  9. * @constructor
  10. *
  11. * @param {Cartesian3} origin The point on the surface of the ellipsoid where the tangent plane touches.
  12. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  13. *
  14. * @exception {DeveloperError} origin must not be at the center of the ellipsoid.
  15. */
  16. function EllipsoidTangentPlane(origin, ellipsoid) {
  17. //>>includeStart('debug', pragmas.debug);
  18. RuntimeError.Check.defined("origin", origin);
  19. //>>includeEnd('debug');
  20. ellipsoid = defaultValue.defaultValue(ellipsoid, Matrix2.Ellipsoid.WGS84);
  21. origin = ellipsoid.scaleToGeodeticSurface(origin);
  22. //>>includeStart('debug', pragmas.debug);
  23. if (!defaultValue.defined(origin)) {
  24. throw new RuntimeError.DeveloperError(
  25. "origin must not be at the center of the ellipsoid."
  26. );
  27. }
  28. //>>includeEnd('debug');
  29. const eastNorthUp = Transforms.Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);
  30. this._ellipsoid = ellipsoid;
  31. this._origin = origin;
  32. this._xAxis = Matrix2.Cartesian3.fromCartesian4(
  33. Matrix2.Matrix4.getColumn(eastNorthUp, 0, scratchCart4)
  34. );
  35. this._yAxis = Matrix2.Cartesian3.fromCartesian4(
  36. Matrix2.Matrix4.getColumn(eastNorthUp, 1, scratchCart4)
  37. );
  38. const normal = Matrix2.Cartesian3.fromCartesian4(
  39. Matrix2.Matrix4.getColumn(eastNorthUp, 2, scratchCart4)
  40. );
  41. this._plane = Plane.Plane.fromPointNormal(origin, normal);
  42. }
  43. Object.defineProperties(EllipsoidTangentPlane.prototype, {
  44. /**
  45. * Gets the ellipsoid.
  46. * @memberof EllipsoidTangentPlane.prototype
  47. * @type {Ellipsoid}
  48. */
  49. ellipsoid: {
  50. get: function () {
  51. return this._ellipsoid;
  52. },
  53. },
  54. /**
  55. * Gets the origin.
  56. * @memberof EllipsoidTangentPlane.prototype
  57. * @type {Cartesian3}
  58. */
  59. origin: {
  60. get: function () {
  61. return this._origin;
  62. },
  63. },
  64. /**
  65. * Gets the plane which is tangent to the ellipsoid.
  66. * @memberof EllipsoidTangentPlane.prototype
  67. * @readonly
  68. * @type {Plane}
  69. */
  70. plane: {
  71. get: function () {
  72. return this._plane;
  73. },
  74. },
  75. /**
  76. * Gets the local X-axis (east) of the tangent plane.
  77. * @memberof EllipsoidTangentPlane.prototype
  78. * @readonly
  79. * @type {Cartesian3}
  80. */
  81. xAxis: {
  82. get: function () {
  83. return this._xAxis;
  84. },
  85. },
  86. /**
  87. * Gets the local Y-axis (north) of the tangent plane.
  88. * @memberof EllipsoidTangentPlane.prototype
  89. * @readonly
  90. * @type {Cartesian3}
  91. */
  92. yAxis: {
  93. get: function () {
  94. return this._yAxis;
  95. },
  96. },
  97. /**
  98. * Gets the local Z-axis (up) of the tangent plane.
  99. * @memberof EllipsoidTangentPlane.prototype
  100. * @readonly
  101. * @type {Cartesian3}
  102. */
  103. zAxis: {
  104. get: function () {
  105. return this._plane.normal;
  106. },
  107. },
  108. });
  109. const tmp = new AxisAlignedBoundingBox.AxisAlignedBoundingBox();
  110. /**
  111. * Creates a new instance from the provided ellipsoid and the center
  112. * point of the provided Cartesians.
  113. *
  114. * @param {Cartesian3[]} cartesians The list of positions surrounding the center point.
  115. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  116. * @returns {EllipsoidTangentPlane} The new instance of EllipsoidTangentPlane.
  117. */
  118. EllipsoidTangentPlane.fromPoints = function (cartesians, ellipsoid) {
  119. //>>includeStart('debug', pragmas.debug);
  120. RuntimeError.Check.defined("cartesians", cartesians);
  121. //>>includeEnd('debug');
  122. const box = AxisAlignedBoundingBox.AxisAlignedBoundingBox.fromPoints(cartesians, tmp);
  123. return new EllipsoidTangentPlane(box.center, ellipsoid);
  124. };
  125. const scratchProjectPointOntoPlaneRay = new IntersectionTests.Ray();
  126. const scratchProjectPointOntoPlaneCartesian3 = new Matrix2.Cartesian3();
  127. /**
  128. * Computes the projection of the provided 3D position onto the 2D plane, radially outward from the {@link EllipsoidTangentPlane.ellipsoid} coordinate system origin.
  129. *
  130. * @param {Cartesian3} cartesian The point to project.
  131. * @param {Cartesian2} [result] The object onto which to store the result.
  132. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided. Undefined if there is no intersection point
  133. */
  134. EllipsoidTangentPlane.prototype.projectPointOntoPlane = function (
  135. cartesian,
  136. result
  137. ) {
  138. //>>includeStart('debug', pragmas.debug);
  139. RuntimeError.Check.defined("cartesian", cartesian);
  140. //>>includeEnd('debug');
  141. const ray = scratchProjectPointOntoPlaneRay;
  142. ray.origin = cartesian;
  143. Matrix2.Cartesian3.normalize(cartesian, ray.direction);
  144. let intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(
  145. ray,
  146. this._plane,
  147. scratchProjectPointOntoPlaneCartesian3
  148. );
  149. if (!defaultValue.defined(intersectionPoint)) {
  150. Matrix2.Cartesian3.negate(ray.direction, ray.direction);
  151. intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(
  152. ray,
  153. this._plane,
  154. scratchProjectPointOntoPlaneCartesian3
  155. );
  156. }
  157. if (defaultValue.defined(intersectionPoint)) {
  158. const v = Matrix2.Cartesian3.subtract(
  159. intersectionPoint,
  160. this._origin,
  161. intersectionPoint
  162. );
  163. const x = Matrix2.Cartesian3.dot(this._xAxis, v);
  164. const y = Matrix2.Cartesian3.dot(this._yAxis, v);
  165. if (!defaultValue.defined(result)) {
  166. return new Matrix2.Cartesian2(x, y);
  167. }
  168. result.x = x;
  169. result.y = y;
  170. return result;
  171. }
  172. return undefined;
  173. };
  174. /**
  175. * Computes the projection of the provided 3D positions onto the 2D plane (where possible), radially outward from the global origin.
  176. * The resulting array may be shorter than the input array - if a single projection is impossible it will not be included.
  177. *
  178. * @see EllipsoidTangentPlane.projectPointOntoPlane
  179. *
  180. * @param {Cartesian3[]} cartesians The array of points to project.
  181. * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
  182. * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided.
  183. */
  184. EllipsoidTangentPlane.prototype.projectPointsOntoPlane = function (
  185. cartesians,
  186. result
  187. ) {
  188. //>>includeStart('debug', pragmas.debug);
  189. RuntimeError.Check.defined("cartesians", cartesians);
  190. //>>includeEnd('debug');
  191. if (!defaultValue.defined(result)) {
  192. result = [];
  193. }
  194. let count = 0;
  195. const length = cartesians.length;
  196. for (let i = 0; i < length; i++) {
  197. const p = this.projectPointOntoPlane(cartesians[i], result[count]);
  198. if (defaultValue.defined(p)) {
  199. result[count] = p;
  200. count++;
  201. }
  202. }
  203. result.length = count;
  204. return result;
  205. };
  206. /**
  207. * Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.
  208. *
  209. * @param {Cartesian3} cartesian The point to project.
  210. * @param {Cartesian2} [result] The object onto which to store the result.
  211. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.
  212. */
  213. EllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function (
  214. cartesian,
  215. result
  216. ) {
  217. //>>includeStart('debug', pragmas.debug);
  218. RuntimeError.Check.defined("cartesian", cartesian);
  219. //>>includeEnd('debug');
  220. if (!defaultValue.defined(result)) {
  221. result = new Matrix2.Cartesian2();
  222. }
  223. const ray = scratchProjectPointOntoPlaneRay;
  224. ray.origin = cartesian;
  225. Matrix2.Cartesian3.clone(this._plane.normal, ray.direction);
  226. let intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(
  227. ray,
  228. this._plane,
  229. scratchProjectPointOntoPlaneCartesian3
  230. );
  231. if (!defaultValue.defined(intersectionPoint)) {
  232. Matrix2.Cartesian3.negate(ray.direction, ray.direction);
  233. intersectionPoint = IntersectionTests.IntersectionTests.rayPlane(
  234. ray,
  235. this._plane,
  236. scratchProjectPointOntoPlaneCartesian3
  237. );
  238. }
  239. const v = Matrix2.Cartesian3.subtract(
  240. intersectionPoint,
  241. this._origin,
  242. intersectionPoint
  243. );
  244. const x = Matrix2.Cartesian3.dot(this._xAxis, v);
  245. const y = Matrix2.Cartesian3.dot(this._yAxis, v);
  246. result.x = x;
  247. result.y = y;
  248. return result;
  249. };
  250. /**
  251. * Computes the projection of the provided 3D positions onto the 2D plane, along the plane normal.
  252. *
  253. * @see EllipsoidTangentPlane.projectPointToNearestOnPlane
  254. *
  255. * @param {Cartesian3[]} cartesians The array of points to project.
  256. * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
  257. * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided. This will have the same length as <code>cartesians</code>.
  258. */
  259. EllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function (
  260. cartesians,
  261. result
  262. ) {
  263. //>>includeStart('debug', pragmas.debug);
  264. RuntimeError.Check.defined("cartesians", cartesians);
  265. //>>includeEnd('debug');
  266. if (!defaultValue.defined(result)) {
  267. result = [];
  268. }
  269. const length = cartesians.length;
  270. result.length = length;
  271. for (let i = 0; i < length; i++) {
  272. result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);
  273. }
  274. return result;
  275. };
  276. const projectPointsOntoEllipsoidScratch = new Matrix2.Cartesian3();
  277. /**
  278. * Computes the projection of the provided 2D position onto the 3D ellipsoid.
  279. *
  280. * @param {Cartesian2} cartesian The points to project.
  281. * @param {Cartesian3} [result] The Cartesian3 instance to store result.
  282. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  283. */
  284. EllipsoidTangentPlane.prototype.projectPointOntoEllipsoid = function (
  285. cartesian,
  286. result
  287. ) {
  288. //>>includeStart('debug', pragmas.debug);
  289. RuntimeError.Check.defined("cartesian", cartesian);
  290. //>>includeEnd('debug');
  291. if (!defaultValue.defined(result)) {
  292. result = new Matrix2.Cartesian3();
  293. }
  294. const ellipsoid = this._ellipsoid;
  295. const origin = this._origin;
  296. const xAxis = this._xAxis;
  297. const yAxis = this._yAxis;
  298. const tmp = projectPointsOntoEllipsoidScratch;
  299. Matrix2.Cartesian3.multiplyByScalar(xAxis, cartesian.x, tmp);
  300. result = Matrix2.Cartesian3.add(origin, tmp, result);
  301. Matrix2.Cartesian3.multiplyByScalar(yAxis, cartesian.y, tmp);
  302. Matrix2.Cartesian3.add(result, tmp, result);
  303. ellipsoid.scaleToGeocentricSurface(result, result);
  304. return result;
  305. };
  306. /**
  307. * Computes the projection of the provided 2D positions onto the 3D ellipsoid.
  308. *
  309. * @param {Cartesian2[]} cartesians The array of points to project.
  310. * @param {Cartesian3[]} [result] The array of Cartesian3 instances onto which to store results.
  311. * @returns {Cartesian3[]} The modified result parameter or a new array of Cartesian3 instances if none was provided.
  312. */
  313. EllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function (
  314. cartesians,
  315. result
  316. ) {
  317. //>>includeStart('debug', pragmas.debug);
  318. RuntimeError.Check.defined("cartesians", cartesians);
  319. //>>includeEnd('debug');
  320. const length = cartesians.length;
  321. if (!defaultValue.defined(result)) {
  322. result = new Array(length);
  323. } else {
  324. result.length = length;
  325. }
  326. for (let i = 0; i < length; ++i) {
  327. result[i] = this.projectPointOntoEllipsoid(cartesians[i], result[i]);
  328. }
  329. return result;
  330. };
  331. exports.EllipsoidTangentPlane = EllipsoidTangentPlane;
  332. }));