Cartesian3.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. import Check from "./Check.js";
  2. import defaultValue from "./defaultValue.js";
  3. import defined from "./defined.js";
  4. import DeveloperError from "./DeveloperError.js";
  5. import CesiumMath from "./Math.js";
  6. /**
  7. * A 3D Cartesian point.
  8. * @alias Cartesian3
  9. * @constructor
  10. *
  11. * @param {number} [x=0.0] The X component.
  12. * @param {number} [y=0.0] The Y component.
  13. * @param {number} [z=0.0] The Z component.
  14. *
  15. * @see Cartesian2
  16. * @see Cartesian4
  17. * @see Packable
  18. */
  19. function Cartesian3(x, y, z) {
  20. /**
  21. * The X component.
  22. * @type {number}
  23. * @default 0.0
  24. */
  25. this.x = defaultValue(x, 0.0);
  26. /**
  27. * The Y component.
  28. * @type {number}
  29. * @default 0.0
  30. */
  31. this.y = defaultValue(y, 0.0);
  32. /**
  33. * The Z component.
  34. * @type {number}
  35. * @default 0.0
  36. */
  37. this.z = defaultValue(z, 0.0);
  38. }
  39. /**
  40. * Converts the provided Spherical into Cartesian3 coordinates.
  41. *
  42. * @param {Spherical} spherical The Spherical to be converted to Cartesian3.
  43. * @param {Cartesian3} [result] The object onto which to store the result.
  44. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  45. */
  46. Cartesian3.fromSpherical = function (spherical, result) {
  47. //>>includeStart('debug', pragmas.debug);
  48. Check.typeOf.object("spherical", spherical);
  49. //>>includeEnd('debug');
  50. if (!defined(result)) {
  51. result = new Cartesian3();
  52. }
  53. const clock = spherical.clock;
  54. const cone = spherical.cone;
  55. const magnitude = defaultValue(spherical.magnitude, 1.0);
  56. const radial = magnitude * Math.sin(cone);
  57. result.x = radial * Math.cos(clock);
  58. result.y = radial * Math.sin(clock);
  59. result.z = magnitude * Math.cos(cone);
  60. return result;
  61. };
  62. /**
  63. * Creates a Cartesian3 instance from x, y and z coordinates.
  64. *
  65. * @param {number} x The x coordinate.
  66. * @param {number} y The y coordinate.
  67. * @param {number} z The z coordinate.
  68. * @param {Cartesian3} [result] The object onto which to store the result.
  69. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  70. */
  71. Cartesian3.fromElements = function (x, y, z, result) {
  72. if (!defined(result)) {
  73. return new Cartesian3(x, y, z);
  74. }
  75. result.x = x;
  76. result.y = y;
  77. result.z = z;
  78. return result;
  79. };
  80. /**
  81. * Duplicates a Cartesian3 instance.
  82. *
  83. * @param {Cartesian3} cartesian The Cartesian to duplicate.
  84. * @param {Cartesian3} [result] The object onto which to store the result.
  85. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
  86. */
  87. Cartesian3.clone = function (cartesian, result) {
  88. if (!defined(cartesian)) {
  89. return undefined;
  90. }
  91. if (!defined(result)) {
  92. return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);
  93. }
  94. result.x = cartesian.x;
  95. result.y = cartesian.y;
  96. result.z = cartesian.z;
  97. return result;
  98. };
  99. /**
  100. * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the
  101. * x, y, and z properties of the Cartesian4 and drops w.
  102. * @function
  103. *
  104. * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.
  105. * @param {Cartesian3} [result] The object onto which to store the result.
  106. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  107. */
  108. Cartesian3.fromCartesian4 = Cartesian3.clone;
  109. /**
  110. * The number of elements used to pack the object into an array.
  111. * @type {number}
  112. */
  113. Cartesian3.packedLength = 3;
  114. /**
  115. * Stores the provided instance into the provided array.
  116. *
  117. * @param {Cartesian3} value The value to pack.
  118. * @param {number[]} array The array to pack into.
  119. * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
  120. *
  121. * @returns {number[]} The array that was packed into
  122. */
  123. Cartesian3.pack = function (value, array, startingIndex) {
  124. //>>includeStart('debug', pragmas.debug);
  125. Check.typeOf.object("value", value);
  126. Check.defined("array", array);
  127. //>>includeEnd('debug');
  128. startingIndex = defaultValue(startingIndex, 0);
  129. array[startingIndex++] = value.x;
  130. array[startingIndex++] = value.y;
  131. array[startingIndex] = value.z;
  132. return array;
  133. };
  134. /**
  135. * Retrieves an instance from a packed array.
  136. *
  137. * @param {number[]} array The packed array.
  138. * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
  139. * @param {Cartesian3} [result] The object into which to store the result.
  140. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  141. */
  142. Cartesian3.unpack = function (array, startingIndex, result) {
  143. //>>includeStart('debug', pragmas.debug);
  144. Check.defined("array", array);
  145. //>>includeEnd('debug');
  146. startingIndex = defaultValue(startingIndex, 0);
  147. if (!defined(result)) {
  148. result = new Cartesian3();
  149. }
  150. result.x = array[startingIndex++];
  151. result.y = array[startingIndex++];
  152. result.z = array[startingIndex];
  153. return result;
  154. };
  155. /**
  156. * Flattens an array of Cartesian3s into an array of components.
  157. *
  158. * @param {Cartesian3[]} array The array of cartesians to pack.
  159. * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.
  160. * @returns {number[]} The packed array.
  161. */
  162. Cartesian3.packArray = function (array, result) {
  163. //>>includeStart('debug', pragmas.debug);
  164. Check.defined("array", array);
  165. //>>includeEnd('debug');
  166. const length = array.length;
  167. const resultLength = length * 3;
  168. if (!defined(result)) {
  169. result = new Array(resultLength);
  170. } else if (!Array.isArray(result) && result.length !== resultLength) {
  171. //>>includeStart('debug', pragmas.debug);
  172. throw new DeveloperError(
  173. "If result is a typed array, it must have exactly array.length * 3 elements"
  174. );
  175. //>>includeEnd('debug');
  176. } else if (result.length !== resultLength) {
  177. result.length = resultLength;
  178. }
  179. for (let i = 0; i < length; ++i) {
  180. Cartesian3.pack(array[i], result, i * 3);
  181. }
  182. return result;
  183. };
  184. /**
  185. * Unpacks an array of cartesian components into an array of Cartesian3s.
  186. *
  187. * @param {number[]} array The array of components to unpack.
  188. * @param {Cartesian3[]} [result] The array onto which to store the result.
  189. * @returns {Cartesian3[]} The unpacked array.
  190. */
  191. Cartesian3.unpackArray = function (array, result) {
  192. //>>includeStart('debug', pragmas.debug);
  193. Check.defined("array", array);
  194. Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 3);
  195. if (array.length % 3 !== 0) {
  196. throw new DeveloperError("array length must be a multiple of 3.");
  197. }
  198. //>>includeEnd('debug');
  199. const length = array.length;
  200. if (!defined(result)) {
  201. result = new Array(length / 3);
  202. } else {
  203. result.length = length / 3;
  204. }
  205. for (let i = 0; i < length; i += 3) {
  206. const index = i / 3;
  207. result[index] = Cartesian3.unpack(array, i, result[index]);
  208. }
  209. return result;
  210. };
  211. /**
  212. * Creates a Cartesian3 from three consecutive elements in an array.
  213. * @function
  214. *
  215. * @param {number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.
  216. * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  217. * @param {Cartesian3} [result] The object onto which to store the result.
  218. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  219. *
  220. * @example
  221. * // Create a Cartesian3 with (1.0, 2.0, 3.0)
  222. * const v = [1.0, 2.0, 3.0];
  223. * const p = Cesium.Cartesian3.fromArray(v);
  224. *
  225. * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array
  226. * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0];
  227. * const p2 = Cesium.Cartesian3.fromArray(v2, 2);
  228. */
  229. Cartesian3.fromArray = Cartesian3.unpack;
  230. /**
  231. * Computes the value of the maximum component for the supplied Cartesian.
  232. *
  233. * @param {Cartesian3} cartesian The cartesian to use.
  234. * @returns {number} The value of the maximum component.
  235. */
  236. Cartesian3.maximumComponent = function (cartesian) {
  237. //>>includeStart('debug', pragmas.debug);
  238. Check.typeOf.object("cartesian", cartesian);
  239. //>>includeEnd('debug');
  240. return Math.max(cartesian.x, cartesian.y, cartesian.z);
  241. };
  242. /**
  243. * Computes the value of the minimum component for the supplied Cartesian.
  244. *
  245. * @param {Cartesian3} cartesian The cartesian to use.
  246. * @returns {number} The value of the minimum component.
  247. */
  248. Cartesian3.minimumComponent = function (cartesian) {
  249. //>>includeStart('debug', pragmas.debug);
  250. Check.typeOf.object("cartesian", cartesian);
  251. //>>includeEnd('debug');
  252. return Math.min(cartesian.x, cartesian.y, cartesian.z);
  253. };
  254. /**
  255. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  256. *
  257. * @param {Cartesian3} first A cartesian to compare.
  258. * @param {Cartesian3} second A cartesian to compare.
  259. * @param {Cartesian3} result The object into which to store the result.
  260. * @returns {Cartesian3} A cartesian with the minimum components.
  261. */
  262. Cartesian3.minimumByComponent = function (first, second, result) {
  263. //>>includeStart('debug', pragmas.debug);
  264. Check.typeOf.object("first", first);
  265. Check.typeOf.object("second", second);
  266. Check.typeOf.object("result", result);
  267. //>>includeEnd('debug');
  268. result.x = Math.min(first.x, second.x);
  269. result.y = Math.min(first.y, second.y);
  270. result.z = Math.min(first.z, second.z);
  271. return result;
  272. };
  273. /**
  274. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  275. *
  276. * @param {Cartesian3} first A cartesian to compare.
  277. * @param {Cartesian3} second A cartesian to compare.
  278. * @param {Cartesian3} result The object into which to store the result.
  279. * @returns {Cartesian3} A cartesian with the maximum components.
  280. */
  281. Cartesian3.maximumByComponent = function (first, second, result) {
  282. //>>includeStart('debug', pragmas.debug);
  283. Check.typeOf.object("first", first);
  284. Check.typeOf.object("second", second);
  285. Check.typeOf.object("result", result);
  286. //>>includeEnd('debug');
  287. result.x = Math.max(first.x, second.x);
  288. result.y = Math.max(first.y, second.y);
  289. result.z = Math.max(first.z, second.z);
  290. return result;
  291. };
  292. /**
  293. * Constrain a value to lie between two values.
  294. *
  295. * @param {Cartesian3} cartesian The value to clamp.
  296. * @param {Cartesian3} min The minimum bound.
  297. * @param {Cartesian3} max The maximum bound.
  298. * @param {Cartesian3} result The object into which to store the result.
  299. * @returns {Cartesian3} The clamped value such that min <= value <= max.
  300. */
  301. Cartesian3.clamp = function (value, min, max, result) {
  302. //>>includeStart('debug', pragmas.debug);
  303. Check.typeOf.object("value", value);
  304. Check.typeOf.object("min", min);
  305. Check.typeOf.object("max", max);
  306. Check.typeOf.object("result", result);
  307. //>>includeEnd('debug');
  308. const x = CesiumMath.clamp(value.x, min.x, max.x);
  309. const y = CesiumMath.clamp(value.y, min.y, max.y);
  310. const z = CesiumMath.clamp(value.z, min.z, max.z);
  311. result.x = x;
  312. result.y = y;
  313. result.z = z;
  314. return result;
  315. };
  316. /**
  317. * Computes the provided Cartesian's squared magnitude.
  318. *
  319. * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
  320. * @returns {number} The squared magnitude.
  321. */
  322. Cartesian3.magnitudeSquared = function (cartesian) {
  323. //>>includeStart('debug', pragmas.debug);
  324. Check.typeOf.object("cartesian", cartesian);
  325. //>>includeEnd('debug');
  326. return (
  327. cartesian.x * cartesian.x +
  328. cartesian.y * cartesian.y +
  329. cartesian.z * cartesian.z
  330. );
  331. };
  332. /**
  333. * Computes the Cartesian's magnitude (length).
  334. *
  335. * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
  336. * @returns {number} The magnitude.
  337. */
  338. Cartesian3.magnitude = function (cartesian) {
  339. return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));
  340. };
  341. const distanceScratch = new Cartesian3();
  342. /**
  343. * Computes the distance between two points.
  344. *
  345. * @param {Cartesian3} left The first point to compute the distance from.
  346. * @param {Cartesian3} right The second point to compute the distance to.
  347. * @returns {number} The distance between two points.
  348. *
  349. * @example
  350. * // Returns 1.0
  351. * const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
  352. */
  353. Cartesian3.distance = function (left, right) {
  354. //>>includeStart('debug', pragmas.debug);
  355. Check.typeOf.object("left", left);
  356. Check.typeOf.object("right", right);
  357. //>>includeEnd('debug');
  358. Cartesian3.subtract(left, right, distanceScratch);
  359. return Cartesian3.magnitude(distanceScratch);
  360. };
  361. /**
  362. * Computes the squared distance between two points. Comparing squared distances
  363. * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
  364. *
  365. * @param {Cartesian3} left The first point to compute the distance from.
  366. * @param {Cartesian3} right The second point to compute the distance to.
  367. * @returns {number} The distance between two points.
  368. *
  369. * @example
  370. * // Returns 4.0, not 2.0
  371. * const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
  372. */
  373. Cartesian3.distanceSquared = function (left, right) {
  374. //>>includeStart('debug', pragmas.debug);
  375. Check.typeOf.object("left", left);
  376. Check.typeOf.object("right", right);
  377. //>>includeEnd('debug');
  378. Cartesian3.subtract(left, right, distanceScratch);
  379. return Cartesian3.magnitudeSquared(distanceScratch);
  380. };
  381. /**
  382. * Computes the normalized form of the supplied Cartesian.
  383. *
  384. * @param {Cartesian3} cartesian The Cartesian to be normalized.
  385. * @param {Cartesian3} result The object onto which to store the result.
  386. * @returns {Cartesian3} The modified result parameter.
  387. */
  388. Cartesian3.normalize = function (cartesian, result) {
  389. //>>includeStart('debug', pragmas.debug);
  390. Check.typeOf.object("cartesian", cartesian);
  391. Check.typeOf.object("result", result);
  392. //>>includeEnd('debug');
  393. const magnitude = Cartesian3.magnitude(cartesian);
  394. result.x = cartesian.x / magnitude;
  395. result.y = cartesian.y / magnitude;
  396. result.z = cartesian.z / magnitude;
  397. //>>includeStart('debug', pragmas.debug);
  398. if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
  399. throw new DeveloperError("normalized result is not a number");
  400. }
  401. //>>includeEnd('debug');
  402. return result;
  403. };
  404. /**
  405. * Computes the dot (scalar) product of two Cartesians.
  406. *
  407. * @param {Cartesian3} left The first Cartesian.
  408. * @param {Cartesian3} right The second Cartesian.
  409. * @returns {number} The dot product.
  410. */
  411. Cartesian3.dot = function (left, right) {
  412. //>>includeStart('debug', pragmas.debug);
  413. Check.typeOf.object("left", left);
  414. Check.typeOf.object("right", right);
  415. //>>includeEnd('debug');
  416. return left.x * right.x + left.y * right.y + left.z * right.z;
  417. };
  418. /**
  419. * Computes the componentwise product of two Cartesians.
  420. *
  421. * @param {Cartesian3} left The first Cartesian.
  422. * @param {Cartesian3} right The second Cartesian.
  423. * @param {Cartesian3} result The object onto which to store the result.
  424. * @returns {Cartesian3} The modified result parameter.
  425. */
  426. Cartesian3.multiplyComponents = function (left, right, result) {
  427. //>>includeStart('debug', pragmas.debug);
  428. Check.typeOf.object("left", left);
  429. Check.typeOf.object("right", right);
  430. Check.typeOf.object("result", result);
  431. //>>includeEnd('debug');
  432. result.x = left.x * right.x;
  433. result.y = left.y * right.y;
  434. result.z = left.z * right.z;
  435. return result;
  436. };
  437. /**
  438. * Computes the componentwise quotient of two Cartesians.
  439. *
  440. * @param {Cartesian3} left The first Cartesian.
  441. * @param {Cartesian3} right The second Cartesian.
  442. * @param {Cartesian3} result The object onto which to store the result.
  443. * @returns {Cartesian3} The modified result parameter.
  444. */
  445. Cartesian3.divideComponents = function (left, right, result) {
  446. //>>includeStart('debug', pragmas.debug);
  447. Check.typeOf.object("left", left);
  448. Check.typeOf.object("right", right);
  449. Check.typeOf.object("result", result);
  450. //>>includeEnd('debug');
  451. result.x = left.x / right.x;
  452. result.y = left.y / right.y;
  453. result.z = left.z / right.z;
  454. return result;
  455. };
  456. /**
  457. * Computes the componentwise sum of two Cartesians.
  458. *
  459. * @param {Cartesian3} left The first Cartesian.
  460. * @param {Cartesian3} right The second Cartesian.
  461. * @param {Cartesian3} result The object onto which to store the result.
  462. * @returns {Cartesian3} The modified result parameter.
  463. */
  464. Cartesian3.add = function (left, right, result) {
  465. //>>includeStart('debug', pragmas.debug);
  466. Check.typeOf.object("left", left);
  467. Check.typeOf.object("right", right);
  468. Check.typeOf.object("result", result);
  469. //>>includeEnd('debug');
  470. result.x = left.x + right.x;
  471. result.y = left.y + right.y;
  472. result.z = left.z + right.z;
  473. return result;
  474. };
  475. /**
  476. * Computes the componentwise difference of two Cartesians.
  477. *
  478. * @param {Cartesian3} left The first Cartesian.
  479. * @param {Cartesian3} right The second Cartesian.
  480. * @param {Cartesian3} result The object onto which to store the result.
  481. * @returns {Cartesian3} The modified result parameter.
  482. */
  483. Cartesian3.subtract = function (left, right, result) {
  484. //>>includeStart('debug', pragmas.debug);
  485. Check.typeOf.object("left", left);
  486. Check.typeOf.object("right", right);
  487. Check.typeOf.object("result", result);
  488. //>>includeEnd('debug');
  489. result.x = left.x - right.x;
  490. result.y = left.y - right.y;
  491. result.z = left.z - right.z;
  492. return result;
  493. };
  494. /**
  495. * Multiplies the provided Cartesian componentwise by the provided scalar.
  496. *
  497. * @param {Cartesian3} cartesian The Cartesian to be scaled.
  498. * @param {number} scalar The scalar to multiply with.
  499. * @param {Cartesian3} result The object onto which to store the result.
  500. * @returns {Cartesian3} The modified result parameter.
  501. */
  502. Cartesian3.multiplyByScalar = function (cartesian, scalar, result) {
  503. //>>includeStart('debug', pragmas.debug);
  504. Check.typeOf.object("cartesian", cartesian);
  505. Check.typeOf.number("scalar", scalar);
  506. Check.typeOf.object("result", result);
  507. //>>includeEnd('debug');
  508. result.x = cartesian.x * scalar;
  509. result.y = cartesian.y * scalar;
  510. result.z = cartesian.z * scalar;
  511. return result;
  512. };
  513. /**
  514. * Divides the provided Cartesian componentwise by the provided scalar.
  515. *
  516. * @param {Cartesian3} cartesian The Cartesian to be divided.
  517. * @param {number} scalar The scalar to divide by.
  518. * @param {Cartesian3} result The object onto which to store the result.
  519. * @returns {Cartesian3} The modified result parameter.
  520. */
  521. Cartesian3.divideByScalar = function (cartesian, scalar, result) {
  522. //>>includeStart('debug', pragmas.debug);
  523. Check.typeOf.object("cartesian", cartesian);
  524. Check.typeOf.number("scalar", scalar);
  525. Check.typeOf.object("result", result);
  526. //>>includeEnd('debug');
  527. result.x = cartesian.x / scalar;
  528. result.y = cartesian.y / scalar;
  529. result.z = cartesian.z / scalar;
  530. return result;
  531. };
  532. /**
  533. * Negates the provided Cartesian.
  534. *
  535. * @param {Cartesian3} cartesian The Cartesian to be negated.
  536. * @param {Cartesian3} result The object onto which to store the result.
  537. * @returns {Cartesian3} The modified result parameter.
  538. */
  539. Cartesian3.negate = function (cartesian, result) {
  540. //>>includeStart('debug', pragmas.debug);
  541. Check.typeOf.object("cartesian", cartesian);
  542. Check.typeOf.object("result", result);
  543. //>>includeEnd('debug');
  544. result.x = -cartesian.x;
  545. result.y = -cartesian.y;
  546. result.z = -cartesian.z;
  547. return result;
  548. };
  549. /**
  550. * Computes the absolute value of the provided Cartesian.
  551. *
  552. * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
  553. * @param {Cartesian3} result The object onto which to store the result.
  554. * @returns {Cartesian3} The modified result parameter.
  555. */
  556. Cartesian3.abs = function (cartesian, result) {
  557. //>>includeStart('debug', pragmas.debug);
  558. Check.typeOf.object("cartesian", cartesian);
  559. Check.typeOf.object("result", result);
  560. //>>includeEnd('debug');
  561. result.x = Math.abs(cartesian.x);
  562. result.y = Math.abs(cartesian.y);
  563. result.z = Math.abs(cartesian.z);
  564. return result;
  565. };
  566. const lerpScratch = new Cartesian3();
  567. /**
  568. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  569. *
  570. * @param {Cartesian3} start The value corresponding to t at 0.0.
  571. * @param {Cartesian3} end The value corresponding to t at 1.0.
  572. * @param {number} t The point along t at which to interpolate.
  573. * @param {Cartesian3} result The object onto which to store the result.
  574. * @returns {Cartesian3} The modified result parameter.
  575. */
  576. Cartesian3.lerp = function (start, end, t, result) {
  577. //>>includeStart('debug', pragmas.debug);
  578. Check.typeOf.object("start", start);
  579. Check.typeOf.object("end", end);
  580. Check.typeOf.number("t", t);
  581. Check.typeOf.object("result", result);
  582. //>>includeEnd('debug');
  583. Cartesian3.multiplyByScalar(end, t, lerpScratch);
  584. result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);
  585. return Cartesian3.add(lerpScratch, result, result);
  586. };
  587. const angleBetweenScratch = new Cartesian3();
  588. const angleBetweenScratch2 = new Cartesian3();
  589. /**
  590. * Returns the angle, in radians, between the provided Cartesians.
  591. *
  592. * @param {Cartesian3} left The first Cartesian.
  593. * @param {Cartesian3} right The second Cartesian.
  594. * @returns {number} The angle between the Cartesians.
  595. */
  596. Cartesian3.angleBetween = function (left, right) {
  597. //>>includeStart('debug', pragmas.debug);
  598. Check.typeOf.object("left", left);
  599. Check.typeOf.object("right", right);
  600. //>>includeEnd('debug');
  601. Cartesian3.normalize(left, angleBetweenScratch);
  602. Cartesian3.normalize(right, angleBetweenScratch2);
  603. const cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
  604. const sine = Cartesian3.magnitude(
  605. Cartesian3.cross(
  606. angleBetweenScratch,
  607. angleBetweenScratch2,
  608. angleBetweenScratch
  609. )
  610. );
  611. return Math.atan2(sine, cosine);
  612. };
  613. const mostOrthogonalAxisScratch = new Cartesian3();
  614. /**
  615. * Returns the axis that is most orthogonal to the provided Cartesian.
  616. *
  617. * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
  618. * @param {Cartesian3} result The object onto which to store the result.
  619. * @returns {Cartesian3} The most orthogonal axis.
  620. */
  621. Cartesian3.mostOrthogonalAxis = function (cartesian, result) {
  622. //>>includeStart('debug', pragmas.debug);
  623. Check.typeOf.object("cartesian", cartesian);
  624. Check.typeOf.object("result", result);
  625. //>>includeEnd('debug');
  626. const f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
  627. Cartesian3.abs(f, f);
  628. if (f.x <= f.y) {
  629. if (f.x <= f.z) {
  630. result = Cartesian3.clone(Cartesian3.UNIT_X, result);
  631. } else {
  632. result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
  633. }
  634. } else if (f.y <= f.z) {
  635. result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
  636. } else {
  637. result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
  638. }
  639. return result;
  640. };
  641. /**
  642. * Projects vector a onto vector b
  643. * @param {Cartesian3} a The vector that needs projecting
  644. * @param {Cartesian3} b The vector to project onto
  645. * @param {Cartesian3} result The result cartesian
  646. * @returns {Cartesian3} The modified result parameter
  647. */
  648. Cartesian3.projectVector = function (a, b, result) {
  649. //>>includeStart('debug', pragmas.debug);
  650. Check.defined("a", a);
  651. Check.defined("b", b);
  652. Check.defined("result", result);
  653. //>>includeEnd('debug');
  654. const scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);
  655. return Cartesian3.multiplyByScalar(b, scalar, result);
  656. };
  657. /**
  658. * Compares the provided Cartesians componentwise and returns
  659. * <code>true</code> if they are equal, <code>false</code> otherwise.
  660. *
  661. * @param {Cartesian3} [left] The first Cartesian.
  662. * @param {Cartesian3} [right] The second Cartesian.
  663. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  664. */
  665. Cartesian3.equals = function (left, right) {
  666. return (
  667. left === right ||
  668. (defined(left) &&
  669. defined(right) &&
  670. left.x === right.x &&
  671. left.y === right.y &&
  672. left.z === right.z)
  673. );
  674. };
  675. /**
  676. * @private
  677. */
  678. Cartesian3.equalsArray = function (cartesian, array, offset) {
  679. return (
  680. cartesian.x === array[offset] &&
  681. cartesian.y === array[offset + 1] &&
  682. cartesian.z === array[offset + 2]
  683. );
  684. };
  685. /**
  686. * Compares the provided Cartesians componentwise and returns
  687. * <code>true</code> if they pass an absolute or relative tolerance test,
  688. * <code>false</code> otherwise.
  689. *
  690. * @param {Cartesian3} [left] The first Cartesian.
  691. * @param {Cartesian3} [right] The second Cartesian.
  692. * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
  693. * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  694. * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  695. */
  696. Cartesian3.equalsEpsilon = function (
  697. left,
  698. right,
  699. relativeEpsilon,
  700. absoluteEpsilon
  701. ) {
  702. return (
  703. left === right ||
  704. (defined(left) &&
  705. defined(right) &&
  706. CesiumMath.equalsEpsilon(
  707. left.x,
  708. right.x,
  709. relativeEpsilon,
  710. absoluteEpsilon
  711. ) &&
  712. CesiumMath.equalsEpsilon(
  713. left.y,
  714. right.y,
  715. relativeEpsilon,
  716. absoluteEpsilon
  717. ) &&
  718. CesiumMath.equalsEpsilon(
  719. left.z,
  720. right.z,
  721. relativeEpsilon,
  722. absoluteEpsilon
  723. ))
  724. );
  725. };
  726. /**
  727. * Computes the cross (outer) product of two Cartesians.
  728. *
  729. * @param {Cartesian3} left The first Cartesian.
  730. * @param {Cartesian3} right The second Cartesian.
  731. * @param {Cartesian3} result The object onto which to store the result.
  732. * @returns {Cartesian3} The cross product.
  733. */
  734. Cartesian3.cross = function (left, right, result) {
  735. //>>includeStart('debug', pragmas.debug);
  736. Check.typeOf.object("left", left);
  737. Check.typeOf.object("right", right);
  738. Check.typeOf.object("result", result);
  739. //>>includeEnd('debug');
  740. const leftX = left.x;
  741. const leftY = left.y;
  742. const leftZ = left.z;
  743. const rightX = right.x;
  744. const rightY = right.y;
  745. const rightZ = right.z;
  746. const x = leftY * rightZ - leftZ * rightY;
  747. const y = leftZ * rightX - leftX * rightZ;
  748. const z = leftX * rightY - leftY * rightX;
  749. result.x = x;
  750. result.y = y;
  751. result.z = z;
  752. return result;
  753. };
  754. /**
  755. * Computes the midpoint between the right and left Cartesian.
  756. * @param {Cartesian3} left The first Cartesian.
  757. * @param {Cartesian3} right The second Cartesian.
  758. * @param {Cartesian3} result The object onto which to store the result.
  759. * @returns {Cartesian3} The midpoint.
  760. */
  761. Cartesian3.midpoint = function (left, right, result) {
  762. //>>includeStart('debug', pragmas.debug);
  763. Check.typeOf.object("left", left);
  764. Check.typeOf.object("right", right);
  765. Check.typeOf.object("result", result);
  766. //>>includeEnd('debug');
  767. result.x = (left.x + right.x) * 0.5;
  768. result.y = (left.y + right.y) * 0.5;
  769. result.z = (left.z + right.z) * 0.5;
  770. return result;
  771. };
  772. /**
  773. * Returns a Cartesian3 position from longitude and latitude values given in degrees.
  774. *
  775. * @param {number} longitude The longitude, in degrees
  776. * @param {number} latitude The latitude, in degrees
  777. * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
  778. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  779. * @param {Cartesian3} [result] The object onto which to store the result.
  780. * @returns {Cartesian3} The position
  781. *
  782. * @example
  783. * const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
  784. */
  785. Cartesian3.fromDegrees = function (
  786. longitude,
  787. latitude,
  788. height,
  789. ellipsoid,
  790. result
  791. ) {
  792. //>>includeStart('debug', pragmas.debug);
  793. Check.typeOf.number("longitude", longitude);
  794. Check.typeOf.number("latitude", latitude);
  795. //>>includeEnd('debug');
  796. longitude = CesiumMath.toRadians(longitude);
  797. latitude = CesiumMath.toRadians(latitude);
  798. return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);
  799. };
  800. let scratchN = new Cartesian3();
  801. let scratchK = new Cartesian3();
  802. const wgs84RadiiSquared = new Cartesian3(
  803. 6378137.0 * 6378137.0,
  804. 6378137.0 * 6378137.0,
  805. 6356752.3142451793 * 6356752.3142451793
  806. );
  807. /**
  808. * Returns a Cartesian3 position from longitude and latitude values given in radians.
  809. *
  810. * @param {number} longitude The longitude, in radians
  811. * @param {number} latitude The latitude, in radians
  812. * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
  813. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  814. * @param {Cartesian3} [result] The object onto which to store the result.
  815. * @returns {Cartesian3} The position
  816. *
  817. * @example
  818. * const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
  819. */
  820. Cartesian3.fromRadians = function (
  821. longitude,
  822. latitude,
  823. height,
  824. ellipsoid,
  825. result
  826. ) {
  827. //>>includeStart('debug', pragmas.debug);
  828. Check.typeOf.number("longitude", longitude);
  829. Check.typeOf.number("latitude", latitude);
  830. //>>includeEnd('debug');
  831. height = defaultValue(height, 0.0);
  832. const radiiSquared = defined(ellipsoid)
  833. ? ellipsoid.radiiSquared
  834. : wgs84RadiiSquared;
  835. const cosLatitude = Math.cos(latitude);
  836. scratchN.x = cosLatitude * Math.cos(longitude);
  837. scratchN.y = cosLatitude * Math.sin(longitude);
  838. scratchN.z = Math.sin(latitude);
  839. scratchN = Cartesian3.normalize(scratchN, scratchN);
  840. Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
  841. const gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));
  842. scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);
  843. scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);
  844. if (!defined(result)) {
  845. result = new Cartesian3();
  846. }
  847. return Cartesian3.add(scratchK, scratchN, result);
  848. };
  849. /**
  850. * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
  851. *
  852. * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
  853. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
  854. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  855. * @returns {Cartesian3[]} The array of positions.
  856. *
  857. * @example
  858. * const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
  859. */
  860. Cartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {
  861. //>>includeStart('debug', pragmas.debug);
  862. Check.defined("coordinates", coordinates);
  863. if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
  864. throw new DeveloperError(
  865. "the number of coordinates must be a multiple of 2 and at least 2"
  866. );
  867. }
  868. //>>includeEnd('debug');
  869. const length = coordinates.length;
  870. if (!defined(result)) {
  871. result = new Array(length / 2);
  872. } else {
  873. result.length = length / 2;
  874. }
  875. for (let i = 0; i < length; i += 2) {
  876. const longitude = coordinates[i];
  877. const latitude = coordinates[i + 1];
  878. const index = i / 2;
  879. result[index] = Cartesian3.fromDegrees(
  880. longitude,
  881. latitude,
  882. 0,
  883. ellipsoid,
  884. result[index]
  885. );
  886. }
  887. return result;
  888. };
  889. /**
  890. * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
  891. *
  892. * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
  893. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
  894. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  895. * @returns {Cartesian3[]} The array of positions.
  896. *
  897. * @example
  898. * const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
  899. */
  900. Cartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {
  901. //>>includeStart('debug', pragmas.debug);
  902. Check.defined("coordinates", coordinates);
  903. if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
  904. throw new DeveloperError(
  905. "the number of coordinates must be a multiple of 2 and at least 2"
  906. );
  907. }
  908. //>>includeEnd('debug');
  909. const length = coordinates.length;
  910. if (!defined(result)) {
  911. result = new Array(length / 2);
  912. } else {
  913. result.length = length / 2;
  914. }
  915. for (let i = 0; i < length; i += 2) {
  916. const longitude = coordinates[i];
  917. const latitude = coordinates[i + 1];
  918. const index = i / 2;
  919. result[index] = Cartesian3.fromRadians(
  920. longitude,
  921. latitude,
  922. 0,
  923. ellipsoid,
  924. result[index]
  925. );
  926. }
  927. return result;
  928. };
  929. /**
  930. * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
  931. *
  932. * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
  933. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  934. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  935. * @returns {Cartesian3[]} The array of positions.
  936. *
  937. * @example
  938. * const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
  939. */
  940. Cartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {
  941. //>>includeStart('debug', pragmas.debug);
  942. Check.defined("coordinates", coordinates);
  943. if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
  944. throw new DeveloperError(
  945. "the number of coordinates must be a multiple of 3 and at least 3"
  946. );
  947. }
  948. //>>includeEnd('debug');
  949. const length = coordinates.length;
  950. if (!defined(result)) {
  951. result = new Array(length / 3);
  952. } else {
  953. result.length = length / 3;
  954. }
  955. for (let i = 0; i < length; i += 3) {
  956. const longitude = coordinates[i];
  957. const latitude = coordinates[i + 1];
  958. const height = coordinates[i + 2];
  959. const index = i / 3;
  960. result[index] = Cartesian3.fromDegrees(
  961. longitude,
  962. latitude,
  963. height,
  964. ellipsoid,
  965. result[index]
  966. );
  967. }
  968. return result;
  969. };
  970. /**
  971. * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
  972. *
  973. * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
  974. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  975. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  976. * @returns {Cartesian3[]} The array of positions.
  977. *
  978. * @example
  979. * const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
  980. */
  981. Cartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {
  982. //>>includeStart('debug', pragmas.debug);
  983. Check.defined("coordinates", coordinates);
  984. if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
  985. throw new DeveloperError(
  986. "the number of coordinates must be a multiple of 3 and at least 3"
  987. );
  988. }
  989. //>>includeEnd('debug');
  990. const length = coordinates.length;
  991. if (!defined(result)) {
  992. result = new Array(length / 3);
  993. } else {
  994. result.length = length / 3;
  995. }
  996. for (let i = 0; i < length; i += 3) {
  997. const longitude = coordinates[i];
  998. const latitude = coordinates[i + 1];
  999. const height = coordinates[i + 2];
  1000. const index = i / 3;
  1001. result[index] = Cartesian3.fromRadians(
  1002. longitude,
  1003. latitude,
  1004. height,
  1005. ellipsoid,
  1006. result[index]
  1007. );
  1008. }
  1009. return result;
  1010. };
  1011. /**
  1012. * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
  1013. *
  1014. * @type {Cartesian3}
  1015. * @constant
  1016. */
  1017. Cartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));
  1018. /**
  1019. * An immutable Cartesian3 instance initialized to (1.0, 1.0, 1.0).
  1020. *
  1021. * @type {Cartesian3}
  1022. * @constant
  1023. */
  1024. Cartesian3.ONE = Object.freeze(new Cartesian3(1.0, 1.0, 1.0));
  1025. /**
  1026. * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).
  1027. *
  1028. * @type {Cartesian3}
  1029. * @constant
  1030. */
  1031. Cartesian3.UNIT_X = Object.freeze(new Cartesian3(1.0, 0.0, 0.0));
  1032. /**
  1033. * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).
  1034. *
  1035. * @type {Cartesian3}
  1036. * @constant
  1037. */
  1038. Cartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));
  1039. /**
  1040. * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).
  1041. *
  1042. * @type {Cartesian3}
  1043. * @constant
  1044. */
  1045. Cartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));
  1046. /**
  1047. * Duplicates this Cartesian3 instance.
  1048. *
  1049. * @param {Cartesian3} [result] The object onto which to store the result.
  1050. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1051. */
  1052. Cartesian3.prototype.clone = function (result) {
  1053. return Cartesian3.clone(this, result);
  1054. };
  1055. /**
  1056. * Compares this Cartesian against the provided Cartesian componentwise and returns
  1057. * <code>true</code> if they are equal, <code>false</code> otherwise.
  1058. *
  1059. * @param {Cartesian3} [right] The right hand side Cartesian.
  1060. * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  1061. */
  1062. Cartesian3.prototype.equals = function (right) {
  1063. return Cartesian3.equals(this, right);
  1064. };
  1065. /**
  1066. * Compares this Cartesian against the provided Cartesian componentwise and returns
  1067. * <code>true</code> if they pass an absolute or relative tolerance test,
  1068. * <code>false</code> otherwise.
  1069. *
  1070. * @param {Cartesian3} [right] The right hand side Cartesian.
  1071. * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
  1072. * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  1073. * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  1074. */
  1075. Cartesian3.prototype.equalsEpsilon = function (
  1076. right,
  1077. relativeEpsilon,
  1078. absoluteEpsilon
  1079. ) {
  1080. return Cartesian3.equalsEpsilon(
  1081. this,
  1082. right,
  1083. relativeEpsilon,
  1084. absoluteEpsilon
  1085. );
  1086. };
  1087. /**
  1088. * Creates a string representing this Cartesian in the format '(x, y, z)'.
  1089. *
  1090. * @returns {string} A string representing this Cartesian in the format '(x, y, z)'.
  1091. */
  1092. Cartesian3.prototype.toString = function () {
  1093. return `(${this.x}, ${this.y}, ${this.z})`;
  1094. };
  1095. export default Cartesian3;