2343 lines
86 KiB
JavaScript
2343 lines
86 KiB
JavaScript
/**
|
|
* @license
|
|
* Cesium - https://github.com/CesiumGS/cesium
|
|
* Version 1.144.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-ACTVJHSP.js";
|
|
import {
|
|
Check_default,
|
|
DeveloperError_default
|
|
} from "./chunk-XLQZNQ4Z.js";
|
|
import {
|
|
defined_default
|
|
} from "./chunk-PCL3Y7H5.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.
|
|
*
|
|
* @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
|
|
* @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
|
|
* // Rotate a point 45 degrees counterclockwise around the x-axis.
|
|
* const p = new Cesium.Cartesian3(5, 6, 7);
|
|
* const m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
|
|
* const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
|
|
*/
|
|
static fromRotationX(angle, result) {
|
|
Check_default.typeOf.number("angle", angle);
|
|
const cosAngle = Math.cos(angle);
|
|
const sinAngle = Math.sin(angle);
|
|
if (!defined_default(result)) {
|
|
return new _Matrix3(
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
cosAngle,
|
|
-sinAngle,
|
|
0,
|
|
sinAngle,
|
|
cosAngle
|
|
);
|
|
}
|
|
result[0] = 1;
|
|
result[1] = 0;
|
|
result[2] = 0;
|
|
result[3] = 0;
|
|
result[4] = cosAngle;
|
|
result[5] = sinAngle;
|
|
result[6] = 0;
|
|
result[7] = -sinAngle;
|
|
result[8] = cosAngle;
|
|
return result;
|
|
}
|
|
/**
|
|
* Creates a rotation matrix around the y-axis.
|
|
*
|
|
* @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
|
|
* @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
|
|
* // Rotate a point 45 degrees counterclockwise around the y-axis.
|
|
* const p = new Cesium.Cartesian3(5, 6, 7);
|
|
* const m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
|
|
* const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
|
|
*/
|
|
static fromRotationY(angle, result) {
|
|
Check_default.typeOf.number("angle", angle);
|
|
const cosAngle = Math.cos(angle);
|
|
const sinAngle = Math.sin(angle);
|
|
if (!defined_default(result)) {
|
|
return new _Matrix3(
|
|
cosAngle,
|
|
0,
|
|
sinAngle,
|
|
0,
|
|
1,
|
|
0,
|
|
-sinAngle,
|
|
0,
|
|
cosAngle
|
|
);
|
|
}
|
|
result[0] = cosAngle;
|
|
result[1] = 0;
|
|
result[2] = -sinAngle;
|
|
result[3] = 0;
|
|
result[4] = 1;
|
|
result[5] = 0;
|
|
result[6] = sinAngle;
|
|
result[7] = 0;
|
|
result[8] = cosAngle;
|
|
return result;
|
|
}
|
|
/**
|
|
* Creates a rotation matrix around the z-axis.
|
|
*
|
|
* @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
|
|
* @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
|
|
* // Rotate a point 45 degrees counterclockwise around the z-axis.
|
|
* const p = new Cesium.Cartesian3(5, 6, 7);
|
|
* const m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
|
|
* const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
|
|
*/
|
|
static fromRotationZ(angle, result) {
|
|
Check_default.typeOf.number("angle", angle);
|
|
const cosAngle = Math.cos(angle);
|
|
const sinAngle = Math.sin(angle);
|
|
if (!defined_default(result)) {
|
|
return new _Matrix3(
|
|
cosAngle,
|
|
-sinAngle,
|
|
0,
|
|
sinAngle,
|
|
cosAngle,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
);
|
|
}
|
|
result[0] = cosAngle;
|
|
result[1] = sinAngle;
|
|
result[2] = 0;
|
|
result[3] = -sinAngle;
|
|
result[4] = cosAngle;
|
|
result[5] = 0;
|
|
result[6] = 0;
|
|
result[7] = 0;
|
|
result[8] = 1;
|
|
return result;
|
|
}
|
|
/**
|
|
* Creates an Array from the provided Matrix3 instance.
|
|
* The array will be in column-major order.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use..
|
|
* @param {number[]} [result] The Array onto which to store the result.
|
|
* @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.
|
|
*/
|
|
static toArray(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
if (!defined_default(result)) {
|
|
return [
|
|
matrix[0],
|
|
matrix[1],
|
|
matrix[2],
|
|
matrix[3],
|
|
matrix[4],
|
|
matrix[5],
|
|
matrix[6],
|
|
matrix[7],
|
|
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;
|
|
}
|
|
/**
|
|
* Computes the array index of the element at the provided row and column.
|
|
*
|
|
* @param {number} column The zero-based index of the column.
|
|
* @param {number} row The zero-based index of the row.
|
|
* @returns {number} The index of the element at the provided row and column.
|
|
*
|
|
* @exception {DeveloperError} row must be 0, 1, or 2.
|
|
* @exception {DeveloperError} column must be 0, 1, or 2.
|
|
*
|
|
* @example
|
|
* const myMatrix = new Cesium.Matrix3();
|
|
* const column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
|
|
* const column1Row0 = myMatrix[column1Row0Index]
|
|
* myMatrix[column1Row0Index] = 10.0;
|
|
*/
|
|
static getElementIndex(column, row) {
|
|
Check_default.typeOf.number.greaterThanOrEquals("row", row, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("row", row, 2);
|
|
Check_default.typeOf.number.greaterThanOrEquals("column", column, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("column", column, 2);
|
|
return column * 3 + row;
|
|
}
|
|
/**
|
|
* Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {number} index The zero-based index of the column to retrieve.
|
|
* @param {Cartesian3} result The object onto which to store the result.
|
|
* @returns {Cartesian3} The modified result parameter.
|
|
*
|
|
* @exception {DeveloperError} index must be 0, 1, or 2.
|
|
*/
|
|
static getColumn(matrix, index, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("index", index, 2);
|
|
Check_default.typeOf.object("result", result);
|
|
const startIndex = index * 3;
|
|
const x = matrix[startIndex];
|
|
const y = matrix[startIndex + 1];
|
|
const z = matrix[startIndex + 2];
|
|
result.x = x;
|
|
result.y = y;
|
|
result.z = z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {number} index The zero-based index of the column to set.
|
|
* @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @exception {DeveloperError} index must be 0, 1, or 2.
|
|
*/
|
|
static setColumn(matrix, index, cartesian, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("index", index, 2);
|
|
Check_default.typeOf.object("cartesian", cartesian);
|
|
Check_default.typeOf.object("result", result);
|
|
result = _Matrix3.clone(matrix, result);
|
|
const startIndex = index * 3;
|
|
result[startIndex] = cartesian.x;
|
|
result[startIndex + 1] = cartesian.y;
|
|
result[startIndex + 2] = cartesian.z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {number} index The zero-based index of the row to retrieve.
|
|
* @param {Cartesian3} result The object onto which to store the result.
|
|
* @returns {Cartesian3} The modified result parameter.
|
|
*
|
|
* @exception {DeveloperError} index must be 0, 1, or 2.
|
|
*/
|
|
static getRow(matrix, index, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("index", index, 2);
|
|
Check_default.typeOf.object("result", result);
|
|
const x = matrix[index];
|
|
const y = matrix[index + 3];
|
|
const z = matrix[index + 6];
|
|
result.x = x;
|
|
result.y = y;
|
|
result.z = z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {number} index The zero-based index of the row to set.
|
|
* @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @exception {DeveloperError} index must be 0, 1, or 2.
|
|
*/
|
|
static setRow(matrix, index, cartesian, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number.greaterThanOrEquals("index", index, 0);
|
|
Check_default.typeOf.number.lessThanOrEquals("index", index, 2);
|
|
Check_default.typeOf.object("cartesian", cartesian);
|
|
Check_default.typeOf.object("result", result);
|
|
result = _Matrix3.clone(matrix, result);
|
|
result[index] = cartesian.x;
|
|
result[index + 3] = cartesian.y;
|
|
result[index + 6] = cartesian.z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes a new matrix that replaces the scale with the provided scale.
|
|
* This assumes the matrix is an affine transformation.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @see Matrix3.setUniformScale
|
|
* @see Matrix3.fromScale
|
|
* @see Matrix3.fromUniformScale
|
|
* @see Matrix3.multiplyByScale
|
|
* @see Matrix3.multiplyByUniformScale
|
|
* @see Matrix3.getScale
|
|
*/
|
|
static setScale(matrix, scale, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("scale", scale);
|
|
Check_default.typeOf.object("result", result);
|
|
const existingScale = _Matrix3.getScale(matrix, scaleScratch1);
|
|
const scaleRatioX = scale.x / existingScale.x;
|
|
const scaleRatioY = scale.y / existingScale.y;
|
|
const scaleRatioZ = scale.z / existingScale.z;
|
|
result[0] = matrix[0] * scaleRatioX;
|
|
result[1] = matrix[1] * scaleRatioX;
|
|
result[2] = matrix[2] * scaleRatioX;
|
|
result[3] = matrix[3] * scaleRatioY;
|
|
result[4] = matrix[4] * scaleRatioY;
|
|
result[5] = matrix[5] * scaleRatioY;
|
|
result[6] = matrix[6] * scaleRatioZ;
|
|
result[7] = matrix[7] * scaleRatioZ;
|
|
result[8] = matrix[8] * scaleRatioZ;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes a new matrix that replaces the scale with the provided uniform scale.
|
|
* This assumes the matrix is an affine transformation.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @param {number} scale The uniform scale that replaces the scale of the provided matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @see Matrix3.setScale
|
|
* @see Matrix3.fromScale
|
|
* @see Matrix3.fromUniformScale
|
|
* @see Matrix3.multiplyByScale
|
|
* @see Matrix3.multiplyByUniformScale
|
|
* @see Matrix3.getScale
|
|
*/
|
|
static setUniformScale(matrix, scale, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number("scale", scale);
|
|
Check_default.typeOf.object("result", result);
|
|
const existingScale = _Matrix3.getScale(matrix, scaleScratch2);
|
|
const scaleRatioX = scale / existingScale.x;
|
|
const scaleRatioY = scale / existingScale.y;
|
|
const scaleRatioZ = scale / existingScale.z;
|
|
result[0] = matrix[0] * scaleRatioX;
|
|
result[1] = matrix[1] * scaleRatioX;
|
|
result[2] = matrix[2] * scaleRatioX;
|
|
result[3] = matrix[3] * scaleRatioY;
|
|
result[4] = matrix[4] * scaleRatioY;
|
|
result[5] = matrix[5] * scaleRatioY;
|
|
result[6] = matrix[6] * scaleRatioZ;
|
|
result[7] = matrix[7] * scaleRatioZ;
|
|
result[8] = matrix[8] * scaleRatioZ;
|
|
return result;
|
|
}
|
|
/**
|
|
* Extracts the non-uniform scale assuming the matrix is an affine transformation.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @param {Cartesian3} result The object onto which to store the result.
|
|
* @returns {Cartesian3} The modified result parameter.
|
|
*
|
|
* @see Matrix3.multiplyByScale
|
|
* @see Matrix3.multiplyByUniformScale
|
|
* @see Matrix3.fromScale
|
|
* @see Matrix3.fromUniformScale
|
|
* @see Matrix3.setScale
|
|
* @see Matrix3.setUniformScale
|
|
*/
|
|
static getScale(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
result.x = Cartesian3_default.magnitude(
|
|
Cartesian3_default.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)
|
|
);
|
|
result.y = Cartesian3_default.magnitude(
|
|
Cartesian3_default.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn)
|
|
);
|
|
result.z = Cartesian3_default.magnitude(
|
|
Cartesian3_default.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn)
|
|
);
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the maximum scale assuming the matrix is an affine transformation.
|
|
* The maximum scale is the maximum length of the column vectors.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @returns {number} The maximum scale.
|
|
*/
|
|
static getMaximumScale(matrix) {
|
|
_Matrix3.getScale(matrix, scaleScratch3);
|
|
return Cartesian3_default.maximumComponent(scaleScratch3);
|
|
}
|
|
/**
|
|
* Sets the rotation assuming the matrix is an affine transformation.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @param {Matrix3} rotation The rotation matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @see Matrix3.getRotation
|
|
*/
|
|
static setRotation(matrix, rotation, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
const scale = _Matrix3.getScale(matrix, scaleScratch4);
|
|
result[0] = rotation[0] * scale.x;
|
|
result[1] = rotation[1] * scale.x;
|
|
result[2] = rotation[2] * scale.x;
|
|
result[3] = rotation[3] * scale.y;
|
|
result[4] = rotation[4] * scale.y;
|
|
result[5] = rotation[5] * scale.y;
|
|
result[6] = rotation[6] * scale.z;
|
|
result[7] = rotation[7] * scale.z;
|
|
result[8] = rotation[8] * scale.z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Extracts the rotation matrix assuming the matrix is an affine transformation.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @see Matrix3.setRotation
|
|
*/
|
|
static getRotation(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
const scale = _Matrix3.getScale(matrix, scaleScratch5);
|
|
result[0] = matrix[0] / scale.x;
|
|
result[1] = matrix[1] / scale.x;
|
|
result[2] = matrix[2] / scale.x;
|
|
result[3] = matrix[3] / scale.y;
|
|
result[4] = matrix[4] / scale.y;
|
|
result[5] = matrix[5] / scale.y;
|
|
result[6] = matrix[6] / scale.z;
|
|
result[7] = matrix[7] / scale.z;
|
|
result[8] = matrix[8] / scale.z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the product of two matrices.
|
|
*
|
|
* @param {Matrix3} left The first matrix.
|
|
* @param {Matrix3} right The second matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static multiply(left, right, result) {
|
|
Check_default.typeOf.object("left", left);
|
|
Check_default.typeOf.object("right", right);
|
|
Check_default.typeOf.object("result", result);
|
|
const column0Row0 = left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
|
|
const column0Row1 = left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
|
|
const column0Row2 = left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
|
|
const column1Row0 = left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
|
|
const column1Row1 = left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
|
|
const column1Row2 = left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
|
|
const column2Row0 = left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
|
|
const column2Row1 = left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
|
|
const column2Row2 = left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
|
|
result[0] = column0Row0;
|
|
result[1] = column0Row1;
|
|
result[2] = column0Row2;
|
|
result[3] = column1Row0;
|
|
result[4] = column1Row1;
|
|
result[5] = column1Row2;
|
|
result[6] = column2Row0;
|
|
result[7] = column2Row1;
|
|
result[8] = column2Row2;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the sum of two matrices.
|
|
*
|
|
* @param {Matrix3} left The first matrix.
|
|
* @param {Matrix3} right The second matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} 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[0] = left[0] + right[0];
|
|
result[1] = left[1] + right[1];
|
|
result[2] = left[2] + right[2];
|
|
result[3] = left[3] + right[3];
|
|
result[4] = left[4] + right[4];
|
|
result[5] = left[5] + right[5];
|
|
result[6] = left[6] + right[6];
|
|
result[7] = left[7] + right[7];
|
|
result[8] = left[8] + right[8];
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the difference of two matrices.
|
|
*
|
|
* @param {Matrix3} left The first matrix.
|
|
* @param {Matrix3} right The second matrix.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} 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[0] = left[0] - right[0];
|
|
result[1] = left[1] - right[1];
|
|
result[2] = left[2] - right[2];
|
|
result[3] = left[3] - right[3];
|
|
result[4] = left[4] - right[4];
|
|
result[5] = left[5] - right[5];
|
|
result[6] = left[6] - right[6];
|
|
result[7] = left[7] - right[7];
|
|
result[8] = left[8] - right[8];
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the product of a matrix and a column vector.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @param {Cartesian3} cartesian The column.
|
|
* @param {Cartesian3} result The object onto which to store the result.
|
|
* @returns {Cartesian3} The modified result parameter.
|
|
*/
|
|
static multiplyByVector(matrix, cartesian, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("cartesian", cartesian);
|
|
Check_default.typeOf.object("result", result);
|
|
const vX = cartesian.x;
|
|
const vY = cartesian.y;
|
|
const vZ = cartesian.z;
|
|
const x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
|
|
const y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
|
|
const z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
|
|
result.x = x;
|
|
result.y = y;
|
|
result.z = z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the product of a matrix and a scalar.
|
|
*
|
|
* @param {Matrix3} matrix The matrix.
|
|
* @param {number} scalar The number to multiply by.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static multiplyByScalar(matrix, scalar, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number("scalar", scalar);
|
|
Check_default.typeOf.object("result", result);
|
|
result[0] = matrix[0] * scalar;
|
|
result[1] = matrix[1] * scalar;
|
|
result[2] = matrix[2] * scalar;
|
|
result[3] = matrix[3] * scalar;
|
|
result[4] = matrix[4] * scalar;
|
|
result[5] = matrix[5] * scalar;
|
|
result[6] = matrix[6] * scalar;
|
|
result[7] = matrix[7] * scalar;
|
|
result[8] = matrix[8] * scalar;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix on the left-hand side.
|
|
* @param {Cartesian3} scale The non-uniform scale on the right-hand side.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
*
|
|
* @example
|
|
* // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
|
|
* Cesium.Matrix3.multiplyByScale(m, scale, m);
|
|
*
|
|
* @see Matrix3.multiplyByUniformScale
|
|
* @see Matrix3.fromScale
|
|
* @see Matrix3.fromUniformScale
|
|
* @see Matrix3.setScale
|
|
* @see Matrix3.setUniformScale
|
|
* @see Matrix3.getScale
|
|
*/
|
|
static multiplyByScale(matrix, scale, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("scale", scale);
|
|
Check_default.typeOf.object("result", result);
|
|
result[0] = matrix[0] * scale.x;
|
|
result[1] = matrix[1] * scale.x;
|
|
result[2] = matrix[2] * scale.x;
|
|
result[3] = matrix[3] * scale.y;
|
|
result[4] = matrix[4] * scale.y;
|
|
result[5] = matrix[5] * scale.y;
|
|
result[6] = matrix[6] * scale.z;
|
|
result[7] = matrix[7] * scale.z;
|
|
result[8] = matrix[8] * scale.z;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix on the left-hand side.
|
|
* @param {number} scale The uniform scale on the right-hand side.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @example
|
|
* // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromUniformScale(scale), m);
|
|
* Cesium.Matrix3.multiplyByUniformScale(m, scale, m);
|
|
*
|
|
* @see Matrix3.multiplyByScale
|
|
* @see Matrix3.fromScale
|
|
* @see Matrix3.fromUniformScale
|
|
* @see Matrix3.setScale
|
|
* @see Matrix3.setUniformScale
|
|
* @see Matrix3.getScale
|
|
*/
|
|
static multiplyByUniformScale(matrix, scale, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.number("scale", scale);
|
|
Check_default.typeOf.object("result", result);
|
|
result[0] = matrix[0] * scale;
|
|
result[1] = matrix[1] * scale;
|
|
result[2] = matrix[2] * scale;
|
|
result[3] = matrix[3] * scale;
|
|
result[4] = matrix[4] * scale;
|
|
result[5] = matrix[5] * scale;
|
|
result[6] = matrix[6] * scale;
|
|
result[7] = matrix[7] * scale;
|
|
result[8] = matrix[8] * scale;
|
|
return result;
|
|
}
|
|
/**
|
|
* Creates a negated copy of the provided matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to negate.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static negate(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
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;
|
|
}
|
|
/**
|
|
* Computes the transpose of the provided matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to transpose.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static transpose(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
const column0Row0 = matrix[0];
|
|
const column0Row1 = matrix[3];
|
|
const column0Row2 = matrix[6];
|
|
const column1Row0 = matrix[1];
|
|
const column1Row1 = matrix[4];
|
|
const column1Row2 = matrix[7];
|
|
const column2Row0 = matrix[2];
|
|
const column2Row1 = matrix[5];
|
|
const column2Row2 = matrix[8];
|
|
result[0] = column0Row0;
|
|
result[1] = column0Row1;
|
|
result[2] = column0Row2;
|
|
result[3] = column1Row0;
|
|
result[4] = column1Row1;
|
|
result[5] = column1Row2;
|
|
result[6] = column2Row0;
|
|
result[7] = column2Row1;
|
|
result[8] = column2Row2;
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the eigenvectors and eigenvalues of a symmetric matrix.
|
|
* <p>
|
|
* Returns a diagonal matrix and unitary matrix such that:
|
|
* <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
|
|
* </p>
|
|
* <p>
|
|
* The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
|
|
* of the unitary matrix are the corresponding eigenvectors.
|
|
* </p>
|
|
*
|
|
* @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
|
|
* @param {EigenDecompositionResult} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
|
|
* @returns {EigenDecompositionResult} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
|
|
*
|
|
* @example
|
|
* const a = //... symetric matrix
|
|
* const result = {
|
|
* unitary : new Cesium.Matrix3(),
|
|
* diagonal : new Cesium.Matrix3()
|
|
* };
|
|
* Cesium.Matrix3.computeEigenDecomposition(a, result);
|
|
*
|
|
* const unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
|
|
* const b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
|
|
* Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
|
|
*
|
|
* const lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
|
|
* const v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
|
|
* const c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
|
|
*/
|
|
static computeEigenDecomposition(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
const tolerance = Math_default.EPSILON20;
|
|
const maxSweeps = 10;
|
|
let count = 0;
|
|
let sweep = 0;
|
|
if (!defined_default(result)) {
|
|
result = {};
|
|
}
|
|
const unitaryMatrix = result.unitary = _Matrix3.clone(
|
|
_Matrix3.IDENTITY,
|
|
result.unitary
|
|
);
|
|
const diagMatrix = result.diagonal = _Matrix3.clone(
|
|
matrix,
|
|
result.diagonal
|
|
);
|
|
const epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
|
|
while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {
|
|
shurDecomposition(diagMatrix, jMatrix);
|
|
_Matrix3.transpose(jMatrix, jMatrixTranspose);
|
|
_Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
|
|
_Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
|
|
_Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
|
|
if (++count > 2) {
|
|
++sweep;
|
|
count = 0;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
|
|
*
|
|
* @param {Matrix3} matrix The matrix with signed elements.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static abs(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
result[0] = Math.abs(matrix[0]);
|
|
result[1] = Math.abs(matrix[1]);
|
|
result[2] = Math.abs(matrix[2]);
|
|
result[3] = Math.abs(matrix[3]);
|
|
result[4] = Math.abs(matrix[4]);
|
|
result[5] = Math.abs(matrix[5]);
|
|
result[6] = Math.abs(matrix[6]);
|
|
result[7] = Math.abs(matrix[7]);
|
|
result[8] = Math.abs(matrix[8]);
|
|
return result;
|
|
}
|
|
/**
|
|
* Computes the determinant of the provided matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to use.
|
|
* @returns {number} The value of the determinant of the matrix.
|
|
*/
|
|
static determinant(matrix) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
const m11 = matrix[0];
|
|
const m21 = matrix[3];
|
|
const m31 = matrix[6];
|
|
const m12 = matrix[1];
|
|
const m22 = matrix[4];
|
|
const m32 = matrix[7];
|
|
const m13 = matrix[2];
|
|
const m23 = matrix[5];
|
|
const m33 = matrix[8];
|
|
return m11 * (m22 * m33 - m23 * m32) + m12 * (m23 * m31 - m21 * m33) + m13 * (m21 * m32 - m22 * m31);
|
|
}
|
|
/**
|
|
* Computes the inverse of the provided matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to invert.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*
|
|
* @exception {DeveloperError} matrix is not invertible.
|
|
*/
|
|
static inverse(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
const m11 = matrix[0];
|
|
const m21 = matrix[1];
|
|
const m31 = matrix[2];
|
|
const m12 = matrix[3];
|
|
const m22 = matrix[4];
|
|
const m32 = matrix[5];
|
|
const m13 = matrix[6];
|
|
const m23 = matrix[7];
|
|
const m33 = matrix[8];
|
|
const determinant = _Matrix3.determinant(matrix);
|
|
if (Math.abs(determinant) <= Math_default.EPSILON15) {
|
|
throw new DeveloperError_default("matrix is not invertible");
|
|
}
|
|
result[0] = m22 * m33 - m23 * m32;
|
|
result[1] = m23 * m31 - m21 * m33;
|
|
result[2] = m21 * m32 - m22 * m31;
|
|
result[3] = m13 * m32 - m12 * m33;
|
|
result[4] = m11 * m33 - m13 * m31;
|
|
result[5] = m12 * m31 - m11 * m32;
|
|
result[6] = m12 * m23 - m13 * m22;
|
|
result[7] = m13 * m21 - m11 * m23;
|
|
result[8] = m11 * m22 - m12 * m21;
|
|
const scale = 1 / determinant;
|
|
return _Matrix3.multiplyByScalar(result, scale, result);
|
|
}
|
|
/**
|
|
* Computes the inverse transpose of a matrix.
|
|
*
|
|
* @param {Matrix3} matrix The matrix to transpose and invert.
|
|
* @param {Matrix3} result The object onto which to store the result.
|
|
* @returns {Matrix3} The modified result parameter.
|
|
*/
|
|
static inverseTranspose(matrix, result) {
|
|
Check_default.typeOf.object("matrix", matrix);
|
|
Check_default.typeOf.object("result", result);
|
|
return _Matrix3.inverse(
|
|
_Matrix3.transpose(matrix, scratchTransposeMatrix),
|
|
result
|
|
);
|
|
}
|
|
/**
|
|
* Compares the provided matrices componentwise and returns
|
|
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
*
|
|
* @param {Matrix3} [left] The first matrix.
|
|
* @param {Matrix3} [right] The second matrix.
|
|
* @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[0] === right[0] && left[1] === right[1] && left[2] === right[2] && left[3] === right[3] && left[4] === right[4] && left[5] === right[5] && left[6] === right[6] && left[7] === right[7] && left[8] === right[8];
|
|
}
|
|
/**
|
|
* Compares the provided matrices componentwise and returns
|
|
* <code>true</code> if they are within the provided epsilon,
|
|
* <code>false</code> otherwise.
|
|
*
|
|
* @param {Matrix3} [left] The first matrix.
|
|
* @param {Matrix3} [right] The second matrix.
|
|
* @param {number} [epsilon=0] The epsilon 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, epsilon) {
|
|
epsilon = epsilon ?? 0;
|
|
return left === right || defined_default(left) && defined_default(right) && Math.abs(left[0] - right[0]) <= epsilon && Math.abs(left[1] - right[1]) <= epsilon && Math.abs(left[2] - right[2]) <= epsilon && Math.abs(left[3] - right[3]) <= epsilon && Math.abs(left[4] - right[4]) <= epsilon && Math.abs(left[5] - right[5]) <= epsilon && Math.abs(left[6] - right[6]) <= epsilon && Math.abs(left[7] - right[7]) <= epsilon && Math.abs(left[8] - right[8]) <= epsilon;
|
|
}
|
|
/**
|
|
* Gets the number of items in the collection.
|
|
*
|
|
* @type {number}
|
|
*/
|
|
get length() {
|
|
return _Matrix3.packedLength;
|
|
}
|
|
/**
|
|
* Duplicates the provided Matrix3 instance.
|
|
*
|
|
* @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.
|
|
*/
|
|
clone(result) {
|
|
return _Matrix3.clone(this, result);
|
|
}
|
|
/**
|
|
* Compares this matrix to the provided matrix componentwise and returns
|
|
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
*
|
|
* @param {Matrix3} [right] The right hand side matrix.
|
|
* @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
*/
|
|
equals(right) {
|
|
return _Matrix3.equals(this, right);
|
|
}
|
|
/**
|
|
* Compares provided matrix and array, starting from a given array offset.
|
|
*
|
|
* @param {Matrix3} matrix
|
|
* @param {number[]} array
|
|
* @param {number} offset
|
|
* @ignore
|
|
*/
|
|
static equalsArray(matrix, array, offset) {
|
|
return matrix[0] === array[offset] && matrix[1] === array[offset + 1] && matrix[2] === array[offset + 2] && matrix[3] === array[offset + 3] && matrix[4] === array[offset + 4] && matrix[5] === array[offset + 5] && matrix[6] === array[offset + 6] && matrix[7] === array[offset + 7] && matrix[8] === array[offset + 8];
|
|
}
|
|
/**
|
|
* Compares this matrix to the provided matrix componentwise and returns
|
|
* <code>true</code> if they are within the provided epsilon,
|
|
* <code>false</code> otherwise.
|
|
*
|
|
* @param {Matrix3} [right] The right hand side matrix.
|
|
* @param {number} [epsilon=0] The epsilon to use for equality testing.
|
|
* @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
|
|
*/
|
|
equalsEpsilon(right, epsilon) {
|
|
return _Matrix3.equalsEpsilon(this, right, epsilon);
|
|
}
|
|
/**
|
|
* Creates a string representing this Matrix with each row being
|
|
* on a separate line and in the format '(column0, column1, column2)'.
|
|
*
|
|
* @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
|
|
*/
|
|
toString() {
|
|
return `(${this[0]}, ${this[3]}, ${this[6]})
|
|
(${this[1]}, ${this[4]}, ${this[7]})
|
|
(${this[2]}, ${this[5]}, ${this[8]})`;
|
|
}
|
|
};
|
|
Matrix3.packedLength = 9;
|
|
Matrix3.fromArray = Matrix3.unpack;
|
|
Matrix3.IDENTITY = Object.freeze(
|
|
new Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1)
|
|
);
|
|
Matrix3.ZERO = Object.freeze(
|
|
new Matrix3(0, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
);
|
|
Matrix3.COLUMN0ROW0 = 0;
|
|
Matrix3.COLUMN0ROW1 = 1;
|
|
Matrix3.COLUMN0ROW2 = 2;
|
|
Matrix3.COLUMN1ROW0 = 3;
|
|
Matrix3.COLUMN1ROW1 = 4;
|
|
Matrix3.COLUMN1ROW2 = 5;
|
|
Matrix3.COLUMN2ROW0 = 6;
|
|
Matrix3.COLUMN2ROW1 = 7;
|
|
Matrix3.COLUMN2ROW2 = 8;
|
|
var scaleScratch1 = new Cartesian3_default();
|
|
var scaleScratch2 = new Cartesian3_default();
|
|
var scratchColumn = new Cartesian3_default();
|
|
var scaleScratch3 = new Cartesian3_default();
|
|
var scaleScratch4 = new Cartesian3_default();
|
|
var scaleScratch5 = new Cartesian3_default();
|
|
var jMatrix = new Matrix3();
|
|
var jMatrixTranspose = new Matrix3();
|
|
var scratchTransposeMatrix = new Matrix3();
|
|
function computeFrobeniusNorm(matrix) {
|
|
let norm = 0;
|
|
for (let i = 0; i < 9; ++i) {
|
|
const temp = matrix[i];
|
|
norm += temp * temp;
|
|
}
|
|
return Math.sqrt(norm);
|
|
}
|
|
var rowVal = [1, 0, 0];
|
|
var colVal = [2, 2, 1];
|
|
function offDiagonalFrobeniusNorm(matrix) {
|
|
let norm = 0;
|
|
for (let i = 0; i < 3; ++i) {
|
|
const temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
|
|
norm += 2 * temp * temp;
|
|
}
|
|
return Math.sqrt(norm);
|
|
}
|
|
function shurDecomposition(matrix, result) {
|
|
const tolerance = Math_default.EPSILON15;
|
|
let maxDiagonal = 0;
|
|
let rotAxis = 1;
|
|
for (let i = 0; i < 3; ++i) {
|
|
const temp = Math.abs(
|
|
// @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
|
|
matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]
|
|
);
|
|
if (temp > maxDiagonal) {
|
|
rotAxis = i;
|
|
maxDiagonal = temp;
|
|
}
|
|
}
|
|
let c = 1;
|
|
let s = 0;
|
|
const p = rowVal[rotAxis];
|
|
const q = colVal[rotAxis];
|
|
if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
|
|
const qq = matrix[Matrix3.getElementIndex(q, q)];
|
|
const pp = matrix[Matrix3.getElementIndex(p, p)];
|
|
const qp = matrix[Matrix3.getElementIndex(q, p)];
|
|
const tau = (qq - pp) / 2 / qp;
|
|
let t;
|
|
if (tau < 0) {
|
|
t = -1 / (-tau + Math.sqrt(1 + tau * tau));
|
|
} else {
|
|
t = 1 / (tau + Math.sqrt(1 + tau * tau));
|
|
}
|
|
c = 1 / Math.sqrt(1 + t * t);
|
|
s = t * c;
|
|
}
|
|
result = Matrix3.clone(Matrix3.IDENTITY, result);
|
|
result[Matrix3.getElementIndex(p, p)] = result[Matrix3.getElementIndex(q, q)] = c;
|
|
result[Matrix3.getElementIndex(q, p)] = s;
|
|
result[Matrix3.getElementIndex(p, q)] = -s;
|
|
return result;
|
|
}
|
|
var Matrix3_default = Matrix3;
|
|
|
|
// packages/engine/Source/Core/Frozen.js
|
|
var Frozen = {};
|
|
Frozen.EMPTY_OBJECT = Object.freeze({});
|
|
Frozen.EMPTY_ARRAY = Object.freeze([]);
|
|
var Frozen_default = Frozen;
|
|
|
|
export {
|
|
Cartesian3_default,
|
|
Matrix3_default,
|
|
Frozen_default
|
|
};
|