cesium
Version:
CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.
1,333 lines (1,329 loc) • 87.8 kB
JavaScript
/**
* @license
* Cesium - https://github.com/CesiumGS/cesium
* Version 1.142.0
*
* Copyright 2011-2022 Cesium Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Columbus View (Pat. Pend.)
*
* Portions licensed separately.
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
*/
import {
Math_default
} from "./chunk-J6BWOHUF.js";
import {
Check_default,
DeveloperError_default
} from "./chunk-AYKR4VBR.js";
import {
defined_default
} from "./chunk-ZP7JMQV4.js";
// packages/engine/Source/Core/Cartesian3.js
var Cartesian3 = class _Cartesian3 {
/**
* @param {number} [x=0.0] The X component.
* @param {number} [y=0.0] The Y component.
* @param {number} [z=0.0] The Z component.
*/
constructor(x, y, z) {
this.x = x ?? 0;
this.y = y ?? 0;
this.z = z ?? 0;
}
/**
* Converts the provided Spherical into Cartesian3 coordinates.
*
* @param {Spherical} spherical The Spherical to be converted to Cartesian3.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
*/
static fromSpherical(spherical, result) {
Check_default.typeOf.object("spherical", spherical);
if (!defined_default(result)) {
result = new _Cartesian3();
}
const clock = spherical.clock;
const cone = spherical.cone;
const magnitude = spherical.magnitude ?? 1;
const radial = magnitude * Math.sin(cone);
result.x = radial * Math.cos(clock);
result.y = radial * Math.sin(clock);
result.z = magnitude * Math.cos(cone);
return result;
}
/**
* Creates a Cartesian3 instance from x, y and z coordinates.
*
* @param {number} x The x coordinate.
* @param {number} y The y coordinate.
* @param {number} z The z coordinate.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
*/
static fromElements(x, y, z, result) {
if (!defined_default(result)) {
return new _Cartesian3(x, y, z);
}
result.x = x;
result.y = y;
result.z = z;
return result;
}
/**
* Duplicates a Cartesian3 instance.
*
* @param {Cartesian3} cartesian The Cartesian to duplicate.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
*/
static clone(cartesian, result) {
if (!defined_default(cartesian)) {
return void 0;
}
if (!defined_default(result)) {
return new _Cartesian3(cartesian.x, cartesian.y, cartesian.z);
}
result.x = cartesian.x;
result.y = cartesian.y;
result.z = cartesian.z;
return result;
}
/**
* Stores the provided instance into the provided array.
*
* @param {Cartesian3} value The value to pack.
* @param {number[]} array The array to pack into.
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
*
* @returns {number[]} The array that was packed into
*/
static pack(value, array, startingIndex) {
Check_default.typeOf.object("value", value);
Check_default.defined("array", array);
startingIndex = startingIndex ?? 0;
array[startingIndex++] = value.x;
array[startingIndex++] = value.y;
array[startingIndex] = value.z;
return array;
}
/**
* Retrieves an instance from a packed array.
*
* @param {number[]} array The packed array.
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {Cartesian3} [result] The object into which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
*/
static unpack(array, startingIndex, result) {
Check_default.defined("array", array);
startingIndex = startingIndex ?? 0;
if (!defined_default(result)) {
result = new _Cartesian3();
}
result.x = array[startingIndex++];
result.y = array[startingIndex++];
result.z = array[startingIndex];
return result;
}
/**
* Flattens an array of Cartesian3s into an array of components.
*
* @param {Cartesian3[]} array The array of cartesians to pack.
* @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.
* @returns {number[]} The packed array.
*/
static packArray(array, result) {
Check_default.defined("array", array);
const length = array.length;
const resultLength = length * 3;
if (!defined_default(result)) {
result = new Array(resultLength);
} else if (!Array.isArray(result) && result.length !== resultLength) {
throw new DeveloperError_default(
"If result is a typed array, it must have exactly array.length * 3 elements"
);
} else if (result.length !== resultLength) {
result.length = resultLength;
}
for (let i = 0; i < length; ++i) {
_Cartesian3.pack(array[i], result, i * 3);
}
return result;
}
/**
* Unpacks an array of cartesian components into an array of Cartesian3s.
*
* @param {number[]} array The array of components to unpack.
* @param {Cartesian3[]} [result] The array onto which to store the result.
* @returns {Cartesian3[]} The unpacked array.
*/
static unpackArray(array, result) {
Check_default.defined("array", array);
Check_default.typeOf.number.greaterThanOrEquals("array.length", array.length, 3);
if (array.length % 3 !== 0) {
throw new DeveloperError_default("array length must be a multiple of 3.");
}
const length = array.length;
if (!defined_default(result)) {
result = new Array(length / 3);
} else {
result.length = length / 3;
}
for (let i = 0; i < length; i += 3) {
const index = i / 3;
result[index] = _Cartesian3.unpack(array, i, result[index]);
}
return result;
}
/**
* Computes the value of the maximum component for the supplied Cartesian.
*
* @param {Cartesian3} cartesian The cartesian to use.
* @returns {number} The value of the maximum component.
*/
static maximumComponent(cartesian) {
Check_default.typeOf.object("cartesian", cartesian);
return Math.max(cartesian.x, cartesian.y, cartesian.z);
}
/**
* Computes the value of the minimum component for the supplied Cartesian.
*
* @param {Cartesian3} cartesian The cartesian to use.
* @returns {number} The value of the minimum component.
*/
static minimumComponent(cartesian) {
Check_default.typeOf.object("cartesian", cartesian);
return Math.min(cartesian.x, cartesian.y, cartesian.z);
}
/**
* Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
*
* @param {Cartesian3} first A cartesian to compare.
* @param {Cartesian3} second A cartesian to compare.
* @param {Cartesian3} result The object into which to store the result.
* @returns {Cartesian3} A cartesian with the minimum components.
*/
static minimumByComponent(first, second, result) {
Check_default.typeOf.object("first", first);
Check_default.typeOf.object("second", second);
Check_default.typeOf.object("result", result);
result.x = Math.min(first.x, second.x);
result.y = Math.min(first.y, second.y);
result.z = Math.min(first.z, second.z);
return result;
}
/**
* Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
*
* @param {Cartesian3} first A cartesian to compare.
* @param {Cartesian3} second A cartesian to compare.
* @param {Cartesian3} result The object into which to store the result.
* @returns {Cartesian3} A cartesian with the maximum components.
*/
static maximumByComponent(first, second, result) {
Check_default.typeOf.object("first", first);
Check_default.typeOf.object("second", second);
Check_default.typeOf.object("result", result);
result.x = Math.max(first.x, second.x);
result.y = Math.max(first.y, second.y);
result.z = Math.max(first.z, second.z);
return result;
}
/**
* Constrain a value to lie between two values.
*
* @param {Cartesian3} value The value to clamp.
* @param {Cartesian3} min The minimum bound.
* @param {Cartesian3} max The maximum bound.
* @param {Cartesian3} result The object into which to store the result.
* @returns {Cartesian3} The clamped value such that min <= value <= max.
*/
static clamp(value, min, max, result) {
Check_default.typeOf.object("value", value);
Check_default.typeOf.object("min", min);
Check_default.typeOf.object("max", max);
Check_default.typeOf.object("result", result);
const x = Math_default.clamp(value.x, min.x, max.x);
const y = Math_default.clamp(value.y, min.y, max.y);
const z = Math_default.clamp(value.z, min.z, max.z);
result.x = x;
result.y = y;
result.z = z;
return result;
}
/**
* Computes the provided Cartesian's squared magnitude.
*
* @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
* @returns {number} The squared magnitude.
*/
static magnitudeSquared(cartesian) {
Check_default.typeOf.object("cartesian", cartesian);
return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z;
}
/**
* Computes the Cartesian's magnitude (length).
*
* @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
* @returns {number} The magnitude.
*/
static magnitude(cartesian) {
return Math.sqrt(_Cartesian3.magnitudeSquared(cartesian));
}
/**
* Computes the distance between two points.
*
* @param {Cartesian3} left The first point to compute the distance from.
* @param {Cartesian3} right The second point to compute the distance to.
* @returns {number} The distance between two points.
*
* @example
* // Returns 1.0
* const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
*/
static distance(left, right) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
_Cartesian3.subtract(left, right, distanceScratch);
return _Cartesian3.magnitude(distanceScratch);
}
/**
* Computes the squared distance between two points. Comparing squared distances
* using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
*
* @param {Cartesian3} left The first point to compute the distance from.
* @param {Cartesian3} right The second point to compute the distance to.
* @returns {number} The distance between two points.
*
* @example
* // Returns 4.0, not 2.0
* const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
*/
static distanceSquared(left, right) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
_Cartesian3.subtract(left, right, distanceScratch);
return _Cartesian3.magnitudeSquared(distanceScratch);
}
/**
* Computes the normalized form of the supplied Cartesian.
*
* @param {Cartesian3} cartesian The Cartesian to be normalized.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static normalize(cartesian, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.object("result", result);
const magnitude = _Cartesian3.magnitude(cartesian);
result.x = cartesian.x / magnitude;
result.y = cartesian.y / magnitude;
result.z = cartesian.z / magnitude;
if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
throw new DeveloperError_default("normalized result is not a number");
}
return result;
}
/**
* Computes the dot (scalar) product of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @returns {number} The dot product.
*/
static dot(left, right) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
return left.x * right.x + left.y * right.y + left.z * right.z;
}
/**
* Computes the componentwise product of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static multiplyComponents(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
result.x = left.x * right.x;
result.y = left.y * right.y;
result.z = left.z * right.z;
return result;
}
/**
* Computes the componentwise quotient of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static divideComponents(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
result.x = left.x / right.x;
result.y = left.y / right.y;
result.z = left.z / right.z;
return result;
}
/**
* Computes the componentwise sum of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static add(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
result.x = left.x + right.x;
result.y = left.y + right.y;
result.z = left.z + right.z;
return result;
}
/**
* Computes the componentwise difference of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static subtract(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
result.x = left.x - right.x;
result.y = left.y - right.y;
result.z = left.z - right.z;
return result;
}
/**
* Multiplies the provided Cartesian componentwise by the provided scalar.
*
* @param {Cartesian3} cartesian The Cartesian to be scaled.
* @param {number} scalar The scalar to multiply with.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static multiplyByScalar(cartesian, scalar, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.number("scalar", scalar);
Check_default.typeOf.object("result", result);
result.x = cartesian.x * scalar;
result.y = cartesian.y * scalar;
result.z = cartesian.z * scalar;
return result;
}
/**
* Divides the provided Cartesian componentwise by the provided scalar.
*
* @param {Cartesian3} cartesian The Cartesian to be divided.
* @param {number} scalar The scalar to divide by.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static divideByScalar(cartesian, scalar, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.number("scalar", scalar);
Check_default.typeOf.object("result", result);
result.x = cartesian.x / scalar;
result.y = cartesian.y / scalar;
result.z = cartesian.z / scalar;
return result;
}
/**
* Negates the provided Cartesian.
*
* @param {Cartesian3} cartesian The Cartesian to be negated.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static negate(cartesian, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.object("result", result);
result.x = -cartesian.x;
result.y = -cartesian.y;
result.z = -cartesian.z;
return result;
}
/**
* Computes the absolute value of the provided Cartesian.
*
* @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static abs(cartesian, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.object("result", result);
result.x = Math.abs(cartesian.x);
result.y = Math.abs(cartesian.y);
result.z = Math.abs(cartesian.z);
return result;
}
/**
* Computes the linear interpolation or extrapolation at t using the provided cartesians.
*
* @param {Cartesian3} start The value corresponding to t at 0.0.
* @param {Cartesian3} end The value corresponding to t at 1.0.
* @param {number} t The point along t at which to interpolate.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter.
*/
static lerp(start, end, t, result) {
Check_default.typeOf.object("start", start);
Check_default.typeOf.object("end", end);
Check_default.typeOf.number("t", t);
Check_default.typeOf.object("result", result);
_Cartesian3.multiplyByScalar(end, t, lerpScratch);
result = _Cartesian3.multiplyByScalar(start, 1 - t, result);
return _Cartesian3.add(lerpScratch, result, result);
}
/**
* Returns the angle, in radians, between the provided Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @returns {number} The angle between the Cartesians.
*/
static angleBetween(left, right) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
_Cartesian3.normalize(left, angleBetweenScratch);
_Cartesian3.normalize(right, angleBetweenScratch2);
const cosine = _Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
const sine = _Cartesian3.magnitude(
_Cartesian3.cross(
angleBetweenScratch,
angleBetweenScratch2,
angleBetweenScratch
)
);
return Math.atan2(sine, cosine);
}
/**
* Returns the axis that is most orthogonal to the provided Cartesian.
*
* @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The most orthogonal axis.
*/
static mostOrthogonalAxis(cartesian, result) {
Check_default.typeOf.object("cartesian", cartesian);
Check_default.typeOf.object("result", result);
const f = _Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
_Cartesian3.abs(f, f);
if (f.x <= f.y) {
if (f.x <= f.z) {
result = _Cartesian3.clone(_Cartesian3.UNIT_X, result);
} else {
result = _Cartesian3.clone(_Cartesian3.UNIT_Z, result);
}
} else if (f.y <= f.z) {
result = _Cartesian3.clone(_Cartesian3.UNIT_Y, result);
} else {
result = _Cartesian3.clone(_Cartesian3.UNIT_Z, result);
}
return result;
}
/**
* Projects vector a onto vector b
* @param {Cartesian3} a The vector that needs projecting
* @param {Cartesian3} b The vector to project onto
* @param {Cartesian3} result The result cartesian
* @returns {Cartesian3} The modified result parameter
*/
static projectVector(a, b, result) {
Check_default.defined("a", a);
Check_default.defined("b", b);
Check_default.defined("result", result);
const scalar = _Cartesian3.dot(a, b) / _Cartesian3.dot(b, b);
return _Cartesian3.multiplyByScalar(b, scalar, result);
}
/**
* Compares the provided Cartesians componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
*
* @param {Cartesian3} [left] The first Cartesian.
* @param {Cartesian3} [right] The second Cartesian.
* @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
static equals(left, right) {
return left === right || defined_default(left) && defined_default(right) && left.x === right.x && left.y === right.y && left.z === right.z;
}
/**
* @param {Cartesian3} cartesian
* @param {number[]} array
* @param {number} offset
* @ignore
*/
static equalsArray(cartesian, array, offset) {
return cartesian.x === array[offset] && cartesian.y === array[offset + 1] && cartesian.z === array[offset + 2];
}
/**
* Compares the provided Cartesians componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {Cartesian3} [left] The first Cartesian.
* @param {Cartesian3} [right] The second Cartesian.
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*/
static equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) {
return left === right || defined_default(left) && defined_default(right) && Math_default.equalsEpsilon(
left.x,
right.x,
relativeEpsilon,
absoluteEpsilon
) && Math_default.equalsEpsilon(
left.y,
right.y,
relativeEpsilon,
absoluteEpsilon
) && Math_default.equalsEpsilon(
left.z,
right.z,
relativeEpsilon,
absoluteEpsilon
);
}
/**
* Computes the cross (outer) product of two Cartesians.
*
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The cross product.
*/
static cross(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
const leftX = left.x;
const leftY = left.y;
const leftZ = left.z;
const rightX = right.x;
const rightY = right.y;
const rightZ = right.z;
const x = leftY * rightZ - leftZ * rightY;
const y = leftZ * rightX - leftX * rightZ;
const z = leftX * rightY - leftY * rightX;
result.x = x;
result.y = y;
result.z = z;
return result;
}
/**
* Computes the midpoint between the right and left Cartesian.
* @param {Cartesian3} left The first Cartesian.
* @param {Cartesian3} right The second Cartesian.
* @param {Cartesian3} result The object onto which to store the result.
* @returns {Cartesian3} The midpoint.
*/
static midpoint(left, right, result) {
Check_default.typeOf.object("left", left);
Check_default.typeOf.object("right", right);
Check_default.typeOf.object("result", result);
result.x = (left.x + right.x) * 0.5;
result.y = (left.y + right.y) * 0.5;
result.z = (left.z + right.z) * 0.5;
return result;
}
/**
* Returns a Cartesian3 position from longitude and latitude values given in degrees.
*
* @param {number} longitude The longitude, in degrees
* @param {number} latitude The latitude, in degrees
* @param {number} [height=0.0] The height, in meters, above the ellipsoid.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The position
*
* @example
* const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
*/
static fromDegrees(longitude, latitude, height, ellipsoid, result) {
Check_default.typeOf.number("longitude", longitude);
Check_default.typeOf.number("latitude", latitude);
longitude = Math_default.toRadians(longitude);
latitude = Math_default.toRadians(latitude);
return _Cartesian3.fromRadians(
longitude,
latitude,
height,
ellipsoid,
result
);
}
/**
* Returns a Cartesian3 position from longitude and latitude values given in radians.
*
* @param {number} longitude The longitude, in radians
* @param {number} latitude The latitude, in radians
* @param {number} [height=0.0] The height, in meters, above the ellipsoid.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The position
*
* @example
* const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
*/
static fromRadians(longitude, latitude, height, ellipsoid, result) {
Check_default.typeOf.number("longitude", longitude);
Check_default.typeOf.number("latitude", latitude);
height = height ?? 0;
const radiiSquared = !defined_default(ellipsoid) ? _Cartesian3._ellipsoidRadiiSquared : ellipsoid.radiiSquared;
const cosLatitude = Math.cos(latitude);
scratchN.x = cosLatitude * Math.cos(longitude);
scratchN.y = cosLatitude * Math.sin(longitude);
scratchN.z = Math.sin(latitude);
scratchN = _Cartesian3.normalize(scratchN, scratchN);
_Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
const gamma = Math.sqrt(_Cartesian3.dot(scratchN, scratchK));
scratchK = _Cartesian3.divideByScalar(scratchK, gamma, scratchK);
scratchN = _Cartesian3.multiplyByScalar(scratchN, height, scratchN);
if (!defined_default(result)) {
result = new _Cartesian3();
}
return _Cartesian3.add(scratchK, scratchN, result);
}
/**
* Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
*
* @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
* @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
* @returns {Cartesian3[]} The array of positions.
*
* @example
* const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
*/
static fromDegreesArray(coordinates, ellipsoid, result) {
Check_default.defined("coordinates", coordinates);
if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
throw new DeveloperError_default(
"the number of coordinates must be a multiple of 2 and at least 2"
);
}
const length = coordinates.length;
if (!defined_default(result)) {
result = new Array(length / 2);
} else {
result.length = length / 2;
}
for (let i = 0; i < length; i += 2) {
const longitude = coordinates[i];
const latitude = coordinates[i + 1];
const index = i / 2;
result[index] = _Cartesian3.fromDegrees(
longitude,
latitude,
0,
ellipsoid,
result[index]
);
}
return result;
}
/**
* Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
*
* @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
* @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
* @returns {Cartesian3[]} The array of positions.
*
* @example
* const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
*/
static fromRadiansArray(coordinates, ellipsoid, result) {
Check_default.defined("coordinates", coordinates);
if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
throw new DeveloperError_default(
"the number of coordinates must be a multiple of 2 and at least 2"
);
}
const length = coordinates.length;
if (!defined_default(result)) {
result = new Array(length / 2);
} else {
result.length = length / 2;
}
for (let i = 0; i < length; i += 2) {
const longitude = coordinates[i];
const latitude = coordinates[i + 1];
const index = i / 2;
result[index] = _Cartesian3.fromRadians(
longitude,
latitude,
0,
ellipsoid,
result[index]
);
}
return result;
}
/**
* Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
*
* @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
* @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
* @returns {Cartesian3[]} The array of positions.
*
* @example
* const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
*/
static fromDegreesArrayHeights(coordinates, ellipsoid, result) {
Check_default.defined("coordinates", coordinates);
if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
throw new DeveloperError_default(
"the number of coordinates must be a multiple of 3 and at least 3"
);
}
const length = coordinates.length;
if (!defined_default(result)) {
result = new Array(length / 3);
} else {
result.length = length / 3;
}
for (let i = 0; i < length; i += 3) {
const longitude = coordinates[i];
const latitude = coordinates[i + 1];
const height = coordinates[i + 2];
const index = i / 3;
result[index] = _Cartesian3.fromDegrees(
longitude,
latitude,
height,
ellipsoid,
result[index]
);
}
return result;
}
/**
* Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
*
* @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
* @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
* @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
* @returns {Cartesian3[]} The array of positions.
*
* @example
* const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
*/
static fromRadiansArrayHeights(coordinates, ellipsoid, result) {
Check_default.defined("coordinates", coordinates);
if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
throw new DeveloperError_default(
"the number of coordinates must be a multiple of 3 and at least 3"
);
}
const length = coordinates.length;
if (!defined_default(result)) {
result = new Array(length / 3);
} else {
result.length = length / 3;
}
for (let i = 0; i < length; i += 3) {
const longitude = coordinates[i];
const latitude = coordinates[i + 1];
const height = coordinates[i + 2];
const index = i / 3;
result[index] = _Cartesian3.fromRadians(
longitude,
latitude,
height,
ellipsoid,
result[index]
);
}
return result;
}
/**
* Duplicates this Cartesian3 instance.
*
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
*/
clone(result) {
return _Cartesian3.clone(this, result);
}
/**
* Compares this Cartesian against the provided Cartesian componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
*
* @param {Cartesian3} [right] The right hand side Cartesian.
* @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
*/
equals(right) {
return _Cartesian3.equals(this, right);
}
/**
* Compares this Cartesian against the provided Cartesian componentwise and returns
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {Cartesian3} [right] The right hand side Cartesian.
* @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
* @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
*/
equalsEpsilon(right, relativeEpsilon, absoluteEpsilon) {
return _Cartesian3.equalsEpsilon(
this,
right,
relativeEpsilon,
absoluteEpsilon
);
}
/**
* Creates a string representing this Cartesian in the format '(x, y, z)'.
*
* @returns {string} A string representing this Cartesian in the format '(x, y, z)'.
*/
toString() {
return `(${this.x}, ${this.y}, ${this.z})`;
}
};
Cartesian3.fromCartesian4 = Cartesian3.clone;
Cartesian3.packedLength = 3;
Cartesian3.fromArray = Cartesian3.unpack;
var distanceScratch = new Cartesian3();
var lerpScratch = new Cartesian3();
var angleBetweenScratch = new Cartesian3();
var angleBetweenScratch2 = new Cartesian3();
var mostOrthogonalAxisScratch = new Cartesian3();
var scratchN = new Cartesian3();
var scratchK = new Cartesian3();
Cartesian3._ellipsoidRadiiSquared = new Cartesian3(
6378137 * 6378137,
6378137 * 6378137,
6356752314245179e-9 * 6356752314245179e-9
);
Cartesian3.ZERO = Object.freeze(new Cartesian3(0, 0, 0));
Cartesian3.ONE = Object.freeze(new Cartesian3(1, 1, 1));
Cartesian3.UNIT_X = Object.freeze(new Cartesian3(1, 0, 0));
Cartesian3.UNIT_Y = Object.freeze(new Cartesian3(0, 1, 0));
Cartesian3.UNIT_Z = Object.freeze(new Cartesian3(0, 0, 1));
var Cartesian3_default = Cartesian3;
// packages/engine/Source/Core/Matrix3.js
var Matrix3 = class _Matrix3 {
/**
* @param {number} [column0Row0=0.0] The value for column 0, row 0.
* @param {number} [column1Row0=0.0] The value for column 1, row 0.
* @param {number} [column2Row0=0.0] The value for column 2, row 0.
* @param {number} [column0Row1=0.0] The value for column 0, row 1.
* @param {number} [column1Row1=0.0] The value for column 1, row 1.
* @param {number} [column2Row1=0.0] The value for column 2, row 1.
* @param {number} [column0Row2=0.0] The value for column 0, row 2.
* @param {number} [column1Row2=0.0] The value for column 1, row 2.
* @param {number} [column2Row2=0.0] The value for column 2, row 2.
*/
constructor(column0Row0, column1Row0, column2Row0, column0Row1, column1Row1, column2Row1, column0Row2, column1Row2, column2Row2) {
this[0] = column0Row0 ?? 0;
this[1] = column0Row1 ?? 0;
this[2] = column0Row2 ?? 0;
this[3] = column1Row0 ?? 0;
this[4] = column1Row1 ?? 0;
this[5] = column1Row2 ?? 0;
this[6] = column2Row0 ?? 0;
this[7] = column2Row1 ?? 0;
this[8] = column2Row2 ?? 0;
}
/**
* Stores the provided instance into the provided array.
*
* @param {Matrix3} value The value to pack.
* @param {number[]} array The array to pack into.
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
*
* @returns {number[]} The array that was packed into
*/
static pack(value, array, startingIndex) {
Check_default.typeOf.object("value", value);
Check_default.defined("array", array);
startingIndex = startingIndex ?? 0;
array[startingIndex++] = value[0];
array[startingIndex++] = value[1];
array[startingIndex++] = value[2];
array[startingIndex++] = value[3];
array[startingIndex++] = value[4];
array[startingIndex++] = value[5];
array[startingIndex++] = value[6];
array[startingIndex++] = value[7];
array[startingIndex++] = value[8];
return array;
}
/**
* Retrieves an instance from a packed array.
*
* @param {number[]} array The packed array.
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {Matrix3} [result] The object into which to store the result.
* @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
*/
static unpack(array, startingIndex, result) {
Check_default.defined("array", array);
startingIndex = startingIndex ?? 0;
if (!defined_default(result)) {
result = new _Matrix3();
}
result[0] = array[startingIndex++];
result[1] = array[startingIndex++];
result[2] = array[startingIndex++];
result[3] = array[startingIndex++];
result[4] = array[startingIndex++];
result[5] = array[startingIndex++];
result[6] = array[startingIndex++];
result[7] = array[startingIndex++];
result[8] = array[startingIndex++];
return result;
}
/**
* Flattens an array of Matrix3s into an array of components. The components
* are stored in column-major order.
*
* @param {Matrix3[]} array The array of matrices to pack.
* @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 9 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 9) elements.
* @returns {number[]} The packed array.
*/
static packArray(array, result) {
Check_default.defined("array", array);
const length = array.length;
const resultLength = length * 9;
if (!defined_default(result)) {
result = new Array(resultLength);
} else if (!Array.isArray(result) && result.length !== resultLength) {
throw new DeveloperError_default(
"If result is a typed array, it must have exactly array.length * 9 elements"
);
} else if (result.length !== resultLength) {
result.length = resultLength;
}
for (let i = 0; i < length; ++i) {
_Matrix3.pack(array[i], result, i * 9);
}
return result;
}
/**
* Unpacks an array of column-major matrix components into an array of Matrix3s.
*
* @param {number[]} array The array of components to unpack.
* @param {Matrix3[]} [result] The array onto which to store the result.
* @returns {Matrix3[]} The unpacked array.
*/
static unpackArray(array, result) {
Check_default.defined("array", array);
Check_default.typeOf.number.greaterThanOrEquals("array.length", array.length, 9);
if (array.length % 9 !== 0) {
throw new DeveloperError_default("array length must be a multiple of 9.");
}
const length = array.length;
if (!defined_default(result)) {
result = new Array(length / 9);
} else {
result.length = length / 9;
}
for (let i = 0; i < length; i += 9) {
const index = i / 9;
result[index] = _Matrix3.unpack(array, i, result[index]);
}
return result;
}
/**
* Duplicates a Matrix3 instance.
*
* @param {Matrix3} matrix The matrix to duplicate.
* @param {Matrix3} [result] The object onto which to store the result.
* @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
*/
static clone(matrix, result) {
if (!defined_default(matrix)) {
return void 0;
}
if (!defined_default(result)) {
return new _Matrix3(
matrix[0],
matrix[3],
matrix[6],
matrix[1],
matrix[4],
matrix[7],
matrix[2],
matrix[5],
matrix[8]
);
}
result[0] = matrix[0];
result[1] = matrix[1];
result[2] = matrix[2];
result[3] = matrix[3];
result[4] = matrix[4];
result[5] = matrix[5];
result[6] = matrix[6];
result[7] = matrix[7];
result[8] = matrix[8];
return result;
}
/**
* Creates a Matrix3 instance from a column-major order array.
*
* @param {number[]} values The column-major order array.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
*/
static fromColumnMajorArray(values, result) {
Check_default.defined("values", values);
return _Matrix3.clone(values, result);
}
/**
* Creates a Matrix3 instance from a row-major order array.
* The resulting matrix will be in column-major order.
*
* @param {number[]} values The row-major order array.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
*/
static fromRowMajorArray(values, result) {
Check_default.defined("values", values);
if (!defined_default(result)) {
return new _Matrix3(
values[0],
values[1],
values[2],
values[3],
values[4],
values[5],
values[6],
values[7],
values[8]
);
}
result[0] = values[0];
result[1] = values[3];
result[2] = values[6];
result[3] = values[1];
result[4] = values[4];
result[5] = values[7];
result[6] = values[2];
result[7] = values[5];
result[8] = values[8];
return result;
}
/**
* Computes a 3x3 rotation matrix from the provided quaternion.
*
* @param {Quaternion} quaternion the quaternion to use.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
*/
static fromQuaternion(quaternion, result) {
Check_default.typeOf.object("quaternion", quaternion);
const x2 = quaternion.x * quaternion.x;
const xy = quaternion.x * quaternion.y;
const xz = quaternion.x * quaternion.z;
const xw = quaternion.x * quaternion.w;
const y2 = quaternion.y * quaternion.y;
const yz = quaternion.y * quaternion.z;
const yw = quaternion.y * quaternion.w;
const z2 = quaternion.z * quaternion.z;
const zw = quaternion.z * quaternion.w;
const w2 = quaternion.w * quaternion.w;
const m00 = x2 - y2 - z2 + w2;
const m01 = 2 * (xy - zw);
const m02 = 2 * (xz + yw);
const m10 = 2 * (xy + zw);
const m11 = -x2 + y2 - z2 + w2;
const m12 = 2 * (yz - xw);
const m20 = 2 * (xz - yw);
const m21 = 2 * (yz + xw);
const m22 = -x2 - y2 + z2 + w2;
if (!defined_default(result)) {
return new _Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
}
result[0] = m00;
result[1] = m10;
result[2] = m20;
result[3] = m01;
result[4] = m11;
result[5] = m21;
result[6] = m02;
result[7] = m12;
result[8] = m22;
return result;
}
/**
* Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
*
* @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
*/
static fromHeadingPitchRoll(headingPitchRoll, result) {
Check_default.typeOf.object("headingPitchRoll", headingPitchRoll);
const cosTheta = Math.cos(-headingPitchRoll.pitch);
const cosPsi = Math.cos(-headingPitchRoll.heading);
const cosPhi = Math.cos(headingPitchRoll.roll);
const sinTheta = Math.sin(-headingPitchRoll.pitch);
const sinPsi = Math.sin(-headingPitchRoll.heading);
const sinPhi = Math.sin(headingPitchRoll.roll);
const m00 = cosTheta * cosPsi;
const m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
const m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
const m10 = cosTheta * sinPsi;
const m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
const m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;
const m20 = -sinTheta;
const m21 = sinPhi * cosTheta;
const m22 = cosPhi * cosTheta;
if (!defined_default(result)) {
return new _Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
}
result[0] = m00;
result[1] = m10;
result[2] = m20;
result[3] = m01;
result[4] = m11;
result[5] = m21;
result[6] = m02;
result[7] = m12;
result[8] = m22;
return result;
}
/**
* Computes a Matrix3 instance representing a non-uniform scale.
*
* @param {Cartesian3} scale The x, y, and z scale factors.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
*
* @example
* // Creates
* // [7.0, 0.0, 0.0]
* // [0.0, 8.0, 0.0]
* // [0.0, 0.0, 9.0]
* const m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
*/
static fromScale(scale, result) {
Check_default.typeOf.object("scale", scale);
if (!defined_default(result)) {
return new _Matrix3(
scale.x,
0,
0,
0,
scale.y,
0,
0,
0,
scale.z
);
}
result[0] = scale.x;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = scale.y;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[8] = scale.z;
return result;
}
/**
* Computes a Matrix3 instance representing a uniform scale.
*
* @param {number} scale The uniform scale factor.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
*
* @example
* // Creates
* // [2.0, 0.0, 0.0]
* // [0.0, 2.0, 0.0]
* // [0.0, 0.0, 2.0]
* const m = Cesium.Matrix3.fromUniformScale(2.0);
*/
static fromUniformScale(scale, result) {
Check_default.typeOf.number("scale", scale);
if (!defined_default(result)) {
return new _Matrix3(scale, 0, 0, 0, scale, 0, 0, 0, scale);
}
result[0] = scale;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = scale;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[8] = scale;
return result;
}
/**
* Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
*
* @param {Cartesian3} vector the vector on the left hand side of the cross product operation.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
*
* @example
* // Creates
* // [0.0, -9.0, 8.0]
* // [9.0, 0.0, -7.0]
* // [-8.0, 7.0, 0.0]
* const m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
*/
static fromCrossProduct(vector, result) {
Check_default.typeOf.object("vector", vector);
if (!defined_default(result)) {
return new _Matrix3(
0,
-vector.z,
vector.y,
vector.z,
0,
-vector.x,
-vector.y,
vector.x,
0
);
}
result[0] = 0;
result[1] = vector.z;
result[2] = -vector.y;
result[3] = -vector.z;
result[4] = 0;
result[5] = vector.x;
result[6] = vector.y;
result[7] = -vector.x;
result[8] = 0;
return result;
}
/**
* Creates a rotation matrix around the x-axis.