true
if they are equal, false
otherwise.
*
* @param {Cartesian3} [left] The first Cartesian.
* @param {Cartesian3} [right] The second Cartesian.
* @returns {boolean} true
if left and right are equal, false
otherwise.
*/
Cartesian3.equals = function (left, right) {
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(right) &&
left.x === right.x &&
left.y === right.y &&
left.z === right.z)
);
};
/**
* @private
*/
Cartesian3.equalsArray = function (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
* true
if they pass an absolute or relative tolerance test,
* false
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} true
if left and right are within the provided epsilon, false
otherwise.
*/
Cartesian3.equalsEpsilon = function (
left,
right,
relativeEpsilon,
absoluteEpsilon
) {
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(right) &&
Math$1.CesiumMath.equalsEpsilon(
left.x,
right.x,
relativeEpsilon,
absoluteEpsilon
) &&
Math$1.CesiumMath.equalsEpsilon(
left.y,
right.y,
relativeEpsilon,
absoluteEpsilon
) &&
Math$1.CesiumMath.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.
*/
Cartesian3.cross = function (left, right, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("left", left);
Check.Check.typeOf.object("right", right);
Check.Check.typeOf.object("result", result);
//>>includeEnd('debug');
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.
*/
Cartesian3.midpoint = function (left, right, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("left", left);
Check.Check.typeOf.object("right", right);
Check.Check.typeOf.object("result", result);
//>>includeEnd('debug');
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.WGS84] 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);
*/
Cartesian3.fromDegrees = function (
longitude,
latitude,
height,
ellipsoid,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number("longitude", longitude);
Check.Check.typeOf.number("latitude", latitude);
//>>includeEnd('debug');
longitude = Math$1.CesiumMath.toRadians(longitude);
latitude = Math$1.CesiumMath.toRadians(latitude);
return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);
};
let scratchN = new Cartesian3();
let scratchK = new Cartesian3();
const wgs84RadiiSquared = new Cartesian3(
6378137.0 * 6378137.0,
6378137.0 * 6378137.0,
6356752.3142451793 * 6356752.3142451793
);
/**
* 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.WGS84] 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);
*/
Cartesian3.fromRadians = function (
longitude,
latitude,
height,
ellipsoid,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number("longitude", longitude);
Check.Check.typeOf.number("latitude", latitude);
//>>includeEnd('debug');
height = defaultValue.defaultValue(height, 0.0);
const radiiSquared = defaultValue.defined(ellipsoid)
? ellipsoid.radiiSquared
: wgs84RadiiSquared;
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 (!defaultValue.defined(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.WGS84] 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]);
*/
Cartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("coordinates", coordinates);
if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
throw new Check.DeveloperError(
"the number of coordinates must be a multiple of 2 and at least 2"
);
}
//>>includeEnd('debug');
const length = coordinates.length;
if (!defaultValue.defined(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.WGS84] 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]);
*/
Cartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("coordinates", coordinates);
if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
throw new Check.DeveloperError(
"the number of coordinates must be a multiple of 2 and at least 2"
);
}
//>>includeEnd('debug');
const length = coordinates.length;
if (!defaultValue.defined(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.WGS84] 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]);
*/
Cartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("coordinates", coordinates);
if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
throw new Check.DeveloperError(
"the number of coordinates must be a multiple of 3 and at least 3"
);
}
//>>includeEnd('debug');
const length = coordinates.length;
if (!defaultValue.defined(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.WGS84] 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]);
*/
Cartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("coordinates", coordinates);
if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
throw new Check.DeveloperError(
"the number of coordinates must be a multiple of 3 and at least 3"
);
}
//>>includeEnd('debug');
const length = coordinates.length;
if (!defaultValue.defined(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;
};
/**
* An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
*
* @type {Cartesian3}
* @constant
*/
Cartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));
/**
* An immutable Cartesian3 instance initialized to (1.0, 1.0, 1.0).
*
* @type {Cartesian3}
* @constant
*/
Cartesian3.ONE = Object.freeze(new Cartesian3(1.0, 1.0, 1.0));
/**
* An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).
*
* @type {Cartesian3}
* @constant
*/
Cartesian3.UNIT_X = Object.freeze(new Cartesian3(1.0, 0.0, 0.0));
/**
* An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).
*
* @type {Cartesian3}
* @constant
*/
Cartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));
/**
* An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).
*
* @type {Cartesian3}
* @constant
*/
Cartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));
/**
* 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.
*/
Cartesian3.prototype.clone = function (result) {
return Cartesian3.clone(this, result);
};
/**
* Compares this Cartesian against the provided Cartesian componentwise and returns
* true
if they are equal, false
otherwise.
*
* @param {Cartesian3} [right] The right hand side Cartesian.
* @returns {boolean} true
if they are equal, false
otherwise.
*/
Cartesian3.prototype.equals = function (right) {
return Cartesian3.equals(this, right);
};
/**
* Compares this Cartesian against the provided Cartesian componentwise and returns
* true
if they pass an absolute or relative tolerance test,
* false
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} true
if they are within the provided epsilon, false
otherwise.
*/
Cartesian3.prototype.equalsEpsilon = function (
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)'.
*/
Cartesian3.prototype.toString = function () {
return `(${this.x}, ${this.y}, ${this.z})`;
};
const scaleToGeodeticSurfaceIntersection = new Cartesian3();
const scaleToGeodeticSurfaceGradient = new Cartesian3();
/**
* Scales the provided Cartesian position along the geodetic surface normal
* so that it is on the surface of this ellipsoid. If the position is
* at the center of the ellipsoid, this function returns undefined.
*
* @param {Cartesian3} cartesian The Cartesian position to scale.
* @param {Cartesian3} oneOverRadii One over radii of the ellipsoid.
* @param {Cartesian3} oneOverRadiiSquared One over radii squared of the ellipsoid.
* @param {number} centerToleranceSquared Tolerance for closeness to the center.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
*
* @function scaleToGeodeticSurface
*
* @private
*/
function scaleToGeodeticSurface(
cartesian,
oneOverRadii,
oneOverRadiiSquared,
centerToleranceSquared,
result
) {
//>>includeStart('debug', pragmas.debug);
if (!defaultValue.defined(cartesian)) {
throw new Check.DeveloperError("cartesian is required.");
}
if (!defaultValue.defined(oneOverRadii)) {
throw new Check.DeveloperError("oneOverRadii is required.");
}
if (!defaultValue.defined(oneOverRadiiSquared)) {
throw new Check.DeveloperError("oneOverRadiiSquared is required.");
}
if (!defaultValue.defined(centerToleranceSquared)) {
throw new Check.DeveloperError("centerToleranceSquared is required.");
}
//>>includeEnd('debug');
const positionX = cartesian.x;
const positionY = cartesian.y;
const positionZ = cartesian.z;
const oneOverRadiiX = oneOverRadii.x;
const oneOverRadiiY = oneOverRadii.y;
const oneOverRadiiZ = oneOverRadii.z;
const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
// Compute the squared ellipsoid norm.
const squaredNorm = x2 + y2 + z2;
const ratio = Math.sqrt(1.0 / squaredNorm);
// As an initial approximation, assume that the radial intersection is the projection point.
const intersection = Cartesian3.multiplyByScalar(
cartesian,
ratio,
scaleToGeodeticSurfaceIntersection
);
// If the position is near the center, the iteration will not converge.
if (squaredNorm < centerToleranceSquared) {
return !isFinite(ratio)
? undefined
: Cartesian3.clone(intersection, result);
}
const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
// Use the gradient at the intersection point in place of the true unit normal.
// The difference in magnitude will be absorbed in the multiplier.
const gradient = scaleToGeodeticSurfaceGradient;
gradient.x = intersection.x * oneOverRadiiSquaredX * 2.0;
gradient.y = intersection.y * oneOverRadiiSquaredY * 2.0;
gradient.z = intersection.z * oneOverRadiiSquaredZ * 2.0;
// Compute the initial guess at the normal vector multiplier, lambda.
let lambda =
((1.0 - ratio) * Cartesian3.magnitude(cartesian)) /
(0.5 * Cartesian3.magnitude(gradient));
let correction = 0.0;
let func;
let denominator;
let xMultiplier;
let yMultiplier;
let zMultiplier;
let xMultiplier2;
let yMultiplier2;
let zMultiplier2;
let xMultiplier3;
let yMultiplier3;
let zMultiplier3;
do {
lambda -= correction;
xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
xMultiplier2 = xMultiplier * xMultiplier;
yMultiplier2 = yMultiplier * yMultiplier;
zMultiplier2 = zMultiplier * zMultiplier;
xMultiplier3 = xMultiplier2 * xMultiplier;
yMultiplier3 = yMultiplier2 * yMultiplier;
zMultiplier3 = zMultiplier2 * zMultiplier;
func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
// "denominator" here refers to the use of this expression in the velocity and acceleration
// computations in the sections to follow.
denominator =
x2 * xMultiplier3 * oneOverRadiiSquaredX +
y2 * yMultiplier3 * oneOverRadiiSquaredY +
z2 * zMultiplier3 * oneOverRadiiSquaredZ;
const derivative = -2.0 * denominator;
correction = func / derivative;
} while (Math.abs(func) > Math$1.CesiumMath.EPSILON12);
if (!defaultValue.defined(result)) {
return new Cartesian3(
positionX * xMultiplier,
positionY * yMultiplier,
positionZ * zMultiplier
);
}
result.x = positionX * xMultiplier;
result.y = positionY * yMultiplier;
result.z = positionZ * zMultiplier;
return result;
}
/**
* A position defined by longitude, latitude, and height.
* @alias Cartographic
* @constructor
*
* @param {number} [longitude=0.0] The longitude, in radians.
* @param {number} [latitude=0.0] The latitude, in radians.
* @param {number} [height=0.0] The height, in meters, above the ellipsoid.
*
* @see Ellipsoid
*/
function Cartographic(longitude, latitude, height) {
/**
* The longitude, in radians.
* @type {number}
* @default 0.0
*/
this.longitude = defaultValue.defaultValue(longitude, 0.0);
/**
* The latitude, in radians.
* @type {number}
* @default 0.0
*/
this.latitude = defaultValue.defaultValue(latitude, 0.0);
/**
* The height, in meters, above the ellipsoid.
* @type {number}
* @default 0.0
*/
this.height = defaultValue.defaultValue(height, 0.0);
}
/**
* Creates a new Cartographic instance from longitude and latitude
* specified 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 {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*/
Cartographic.fromRadians = function (longitude, latitude, height, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number("longitude", longitude);
Check.Check.typeOf.number("latitude", latitude);
//>>includeEnd('debug');
height = defaultValue.defaultValue(height, 0.0);
if (!defaultValue.defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
return result;
};
/**
* Creates a new Cartographic instance from longitude and latitude
* specified in degrees. The values in the resulting object will
* be in radians.
*
* @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 {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*/
Cartographic.fromDegrees = function (longitude, latitude, height, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number("longitude", longitude);
Check.Check.typeOf.number("latitude", latitude);
//>>includeEnd('debug');
longitude = Math$1.CesiumMath.toRadians(longitude);
latitude = Math$1.CesiumMath.toRadians(latitude);
return Cartographic.fromRadians(longitude, latitude, height, result);
};
const cartesianToCartographicN$1 = new Cartesian3();
const cartesianToCartographicP$1 = new Cartesian3();
const cartesianToCartographicH$1 = new Cartesian3();
const wgs84OneOverRadii = new Cartesian3(
1.0 / 6378137.0,
1.0 / 6378137.0,
1.0 / 6356752.3142451793
);
const wgs84OneOverRadiiSquared = new Cartesian3(
1.0 / (6378137.0 * 6378137.0),
1.0 / (6378137.0 * 6378137.0),
1.0 / (6356752.3142451793 * 6356752.3142451793)
);
const wgs84CenterToleranceSquared = Math$1.CesiumMath.EPSILON1;
/**
* Creates a new Cartographic instance from a Cartesian position. The values in the
* resulting object will be in radians.
*
* @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
*/
Cartographic.fromCartesian = function (cartesian, ellipsoid, result) {
const oneOverRadii = defaultValue.defined(ellipsoid)
? ellipsoid.oneOverRadii
: wgs84OneOverRadii;
const oneOverRadiiSquared = defaultValue.defined(ellipsoid)
? ellipsoid.oneOverRadiiSquared
: wgs84OneOverRadiiSquared;
const centerToleranceSquared = defaultValue.defined(ellipsoid)
? ellipsoid._centerToleranceSquared
: wgs84CenterToleranceSquared;
//`cartesian is required.` is thrown from scaleToGeodeticSurface
const p = scaleToGeodeticSurface(
cartesian,
oneOverRadii,
oneOverRadiiSquared,
centerToleranceSquared,
cartesianToCartographicP$1
);
if (!defaultValue.defined(p)) {
return undefined;
}
let n = Cartesian3.multiplyComponents(
p,
oneOverRadiiSquared,
cartesianToCartographicN$1
);
n = Cartesian3.normalize(n, n);
const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH$1);
const longitude = Math.atan2(n.y, n.x);
const latitude = Math.asin(n.z);
const height =
Math$1.CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
if (!defaultValue.defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
return result;
};
/**
* Creates a new Cartesian3 instance from a Cartographic input. The values in the inputted
* object should be in radians.
*
* @param {Cartographic} cartographic Input to be converted into a Cartesian3 output.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The position
*/
Cartographic.toCartesian = function (cartographic, ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("cartographic", cartographic);
//>>includeEnd('debug');
return Cartesian3.fromRadians(
cartographic.longitude,
cartographic.latitude,
cartographic.height,
ellipsoid,
result
);
};
/**
* Duplicates a Cartographic instance.
*
* @param {Cartographic} cartographic The cartographic to duplicate.
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided. (Returns undefined if cartographic is undefined)
*/
Cartographic.clone = function (cartographic, result) {
if (!defaultValue.defined(cartographic)) {
return undefined;
}
if (!defaultValue.defined(result)) {
return new Cartographic(
cartographic.longitude,
cartographic.latitude,
cartographic.height
);
}
result.longitude = cartographic.longitude;
result.latitude = cartographic.latitude;
result.height = cartographic.height;
return result;
};
/**
* Compares the provided cartographics componentwise and returns
* true
if they are equal, false
otherwise.
*
* @param {Cartographic} [left] The first cartographic.
* @param {Cartographic} [right] The second cartographic.
* @returns {boolean} true
if left and right are equal, false
otherwise.
*/
Cartographic.equals = function (left, right) {
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(right) &&
left.longitude === right.longitude &&
left.latitude === right.latitude &&
left.height === right.height)
);
};
/**
* Compares the provided cartographics componentwise and returns
* true
if they are within the provided epsilon,
* false
otherwise.
*
* @param {Cartographic} [left] The first cartographic.
* @param {Cartographic} [right] The second cartographic.
* @param {number} [epsilon=0] The epsilon to use for equality testing.
* @returns {boolean} true
if left and right are within the provided epsilon, false
otherwise.
*/
Cartographic.equalsEpsilon = function (left, right, epsilon) {
epsilon = defaultValue.defaultValue(epsilon, 0);
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(right) &&
Math.abs(left.longitude - right.longitude) <= epsilon &&
Math.abs(left.latitude - right.latitude) <= epsilon &&
Math.abs(left.height - right.height) <= epsilon)
);
};
/**
* An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).
*
* @type {Cartographic}
* @constant
*/
Cartographic.ZERO = Object.freeze(new Cartographic(0.0, 0.0, 0.0));
/**
* Duplicates this instance.
*
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
*/
Cartographic.prototype.clone = function (result) {
return Cartographic.clone(this, result);
};
/**
* Compares the provided against this cartographic componentwise and returns
* true
if they are equal, false
otherwise.
*
* @param {Cartographic} [right] The second cartographic.
* @returns {boolean} true
if left and right are equal, false
otherwise.
*/
Cartographic.prototype.equals = function (right) {
return Cartographic.equals(this, right);
};
/**
* Compares the provided against this cartographic componentwise and returns
* true
if they are within the provided epsilon,
* false
otherwise.
*
* @param {Cartographic} [right] The second cartographic.
* @param {number} [epsilon=0] The epsilon to use for equality testing.
* @returns {boolean} true
if left and right are within the provided epsilon, false
otherwise.
*/
Cartographic.prototype.equalsEpsilon = function (right, epsilon) {
return Cartographic.equalsEpsilon(this, right, epsilon);
};
/**
* Creates a string representing this cartographic in the format '(longitude, latitude, height)'.
*
* @returns {string} A string representing the provided cartographic in the format '(longitude, latitude, height)'.
*/
Cartographic.prototype.toString = function () {
return `(${this.longitude}, ${this.latitude}, ${this.height})`;
};
function initialize(ellipsoid, x, y, z) {
x = defaultValue.defaultValue(x, 0.0);
y = defaultValue.defaultValue(y, 0.0);
z = defaultValue.defaultValue(z, 0.0);
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number.greaterThanOrEquals("x", x, 0.0);
Check.Check.typeOf.number.greaterThanOrEquals("y", y, 0.0);
Check.Check.typeOf.number.greaterThanOrEquals("z", z, 0.0);
//>>includeEnd('debug');
ellipsoid._radii = new Cartesian3(x, y, z);
ellipsoid._radiiSquared = new Cartesian3(x * x, y * y, z * z);
ellipsoid._radiiToTheFourth = new Cartesian3(
x * x * x * x,
y * y * y * y,
z * z * z * z
);
ellipsoid._oneOverRadii = new Cartesian3(
x === 0.0 ? 0.0 : 1.0 / x,
y === 0.0 ? 0.0 : 1.0 / y,
z === 0.0 ? 0.0 : 1.0 / z
);
ellipsoid._oneOverRadiiSquared = new Cartesian3(
x === 0.0 ? 0.0 : 1.0 / (x * x),
y === 0.0 ? 0.0 : 1.0 / (y * y),
z === 0.0 ? 0.0 : 1.0 / (z * z)
);
ellipsoid._minimumRadius = Math.min(x, y, z);
ellipsoid._maximumRadius = Math.max(x, y, z);
ellipsoid._centerToleranceSquared = Math$1.CesiumMath.EPSILON1;
if (ellipsoid._radiiSquared.z !== 0) {
ellipsoid._squaredXOverSquaredZ =
ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;
}
}
/**
* A quadratic surface defined in Cartesian coordinates by the equation
* (x / a)^2 + (y / b)^2 + (z / c)^2 = 1
. Primarily used
* by Cesium to represent the shape of planetary bodies.
*
* Rather than constructing this object directly, one of the provided
* constants is normally used.
* @alias Ellipsoid
* @constructor
*
* @param {number} [x=0] The radius in the x direction.
* @param {number} [y=0] The radius in the y direction.
* @param {number} [z=0] The radius in the z direction.
*
* @exception {DeveloperError} All radii components must be greater than or equal to zero.
*
* @see Ellipsoid.fromCartesian3
* @see Ellipsoid.WGS84
* @see Ellipsoid.UNIT_SPHERE
*/
function Ellipsoid(x, y, z) {
this._radii = undefined;
this._radiiSquared = undefined;
this._radiiToTheFourth = undefined;
this._oneOverRadii = undefined;
this._oneOverRadiiSquared = undefined;
this._minimumRadius = undefined;
this._maximumRadius = undefined;
this._centerToleranceSquared = undefined;
this._squaredXOverSquaredZ = undefined;
initialize(this, x, y, z);
}
Object.defineProperties(Ellipsoid.prototype, {
/**
* Gets the radii of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {Cartesian3}
* @readonly
*/
radii: {
get: function () {
return this._radii;
},
},
/**
* Gets the squared radii of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {Cartesian3}
* @readonly
*/
radiiSquared: {
get: function () {
return this._radiiSquared;
},
},
/**
* Gets the radii of the ellipsoid raise to the fourth power.
* @memberof Ellipsoid.prototype
* @type {Cartesian3}
* @readonly
*/
radiiToTheFourth: {
get: function () {
return this._radiiToTheFourth;
},
},
/**
* Gets one over the radii of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {Cartesian3}
* @readonly
*/
oneOverRadii: {
get: function () {
return this._oneOverRadii;
},
},
/**
* Gets one over the squared radii of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {Cartesian3}
* @readonly
*/
oneOverRadiiSquared: {
get: function () {
return this._oneOverRadiiSquared;
},
},
/**
* Gets the minimum radius of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {number}
* @readonly
*/
minimumRadius: {
get: function () {
return this._minimumRadius;
},
},
/**
* Gets the maximum radius of the ellipsoid.
* @memberof Ellipsoid.prototype
* @type {number}
* @readonly
*/
maximumRadius: {
get: function () {
return this._maximumRadius;
},
},
});
/**
* Duplicates an Ellipsoid instance.
*
* @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.
* @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
* instance should be created.
* @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)
*/
Ellipsoid.clone = function (ellipsoid, result) {
if (!defaultValue.defined(ellipsoid)) {
return undefined;
}
const radii = ellipsoid._radii;
if (!defaultValue.defined(result)) {
return new Ellipsoid(radii.x, radii.y, radii.z);
}
Cartesian3.clone(radii, result._radii);
Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);
Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);
Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);
Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);
result._minimumRadius = ellipsoid._minimumRadius;
result._maximumRadius = ellipsoid._maximumRadius;
result._centerToleranceSquared = ellipsoid._centerToleranceSquared;
return result;
};
/**
* Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.
*
* @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.
* @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
* instance should be created.
* @returns {Ellipsoid} A new Ellipsoid instance.
*
* @exception {DeveloperError} All radii components must be greater than or equal to zero.
*
* @see Ellipsoid.WGS84
* @see Ellipsoid.UNIT_SPHERE
*/
Ellipsoid.fromCartesian3 = function (cartesian, result) {
if (!defaultValue.defined(result)) {
result = new Ellipsoid();
}
if (!defaultValue.defined(cartesian)) {
return result;
}
initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
};
/**
* An Ellipsoid instance initialized to the WGS84 standard.
*
* @type {Ellipsoid}
* @constant
*/
Ellipsoid.WGS84 = Object.freeze(
new Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793)
);
/**
* An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).
*
* @type {Ellipsoid}
* @constant
*/
Ellipsoid.UNIT_SPHERE = Object.freeze(new Ellipsoid(1.0, 1.0, 1.0));
/**
* An Ellipsoid instance initialized to a sphere with the lunar radius.
*
* @type {Ellipsoid}
* @constant
*/
Ellipsoid.MOON = Object.freeze(
new Ellipsoid(
Math$1.CesiumMath.LUNAR_RADIUS,
Math$1.CesiumMath.LUNAR_RADIUS,
Math$1.CesiumMath.LUNAR_RADIUS
)
);
/**
* Duplicates an Ellipsoid instance.
*
* @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
* instance should be created.
* @returns {Ellipsoid} The cloned Ellipsoid.
*/
Ellipsoid.prototype.clone = function (result) {
return Ellipsoid.clone(this, result);
};
/**
* The number of elements used to pack the object into an array.
* @type {number}
*/
Ellipsoid.packedLength = Cartesian3.packedLength;
/**
* Stores the provided instance into the provided array.
*
* @param {Ellipsoid} 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
*/
Ellipsoid.pack = function (value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("value", value);
Check.Check.defined("array", array);
//>>includeEnd('debug');
startingIndex = defaultValue.defaultValue(startingIndex, 0);
Cartesian3.pack(value._radii, array, startingIndex);
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 {Ellipsoid} [result] The object into which to store the result.
* @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.
*/
Ellipsoid.unpack = function (array, startingIndex, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("array", array);
//>>includeEnd('debug');
startingIndex = defaultValue.defaultValue(startingIndex, 0);
const radii = Cartesian3.unpack(array, startingIndex);
return Ellipsoid.fromCartesian3(radii, result);
};
/**
* Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.
* @function
*
* @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
*/
Ellipsoid.prototype.geocentricSurfaceNormal = Cartesian3.normalize;
/**
* Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
*
* @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
*/
Ellipsoid.prototype.geodeticSurfaceNormalCartographic = function (
cartographic,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("cartographic", cartographic);
//>>includeEnd('debug');
const longitude = cartographic.longitude;
const latitude = cartographic.latitude;
const cosLatitude = Math.cos(latitude);
const x = cosLatitude * Math.cos(longitude);
const y = cosLatitude * Math.sin(longitude);
const z = Math.sin(latitude);
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
result.x = x;
result.y = y;
result.z = z;
return Cartesian3.normalize(result, result);
};
/**
* Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
*
* @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided, or undefined if a normal cannot be found.
*/
Ellipsoid.prototype.geodeticSurfaceNormal = function (cartesian, result) {
if (
Cartesian3.equalsEpsilon(cartesian, Cartesian3.ZERO, Math$1.CesiumMath.EPSILON14)
) {
return undefined;
}
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
result = Cartesian3.multiplyComponents(
cartesian,
this._oneOverRadiiSquared,
result
);
return Cartesian3.normalize(result, result);
};
const cartographicToCartesianNormal = new Cartesian3();
const cartographicToCartesianK = new Cartesian3();
/**
* Converts the provided cartographic to Cartesian representation.
*
* @param {Cartographic} cartographic The cartographic position.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
*
* @example
* //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.
* const position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);
* const cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
*/
Ellipsoid.prototype.cartographicToCartesian = function (cartographic, result) {
//`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.
const n = cartographicToCartesianNormal;
const k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, n);
Cartesian3.multiplyComponents(this._radiiSquared, n, k);
const gamma = Math.sqrt(Cartesian3.dot(n, k));
Cartesian3.divideByScalar(k, gamma, k);
Cartesian3.multiplyByScalar(n, cartographic.height, n);
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
return Cartesian3.add(k, n, result);
};
/**
* Converts the provided array of cartographics to an array of Cartesians.
*
* @param {Cartographic[]} cartographics An array of cartographic positions.
* @param {Cartesian3[]} [result] The object onto which to store the result.
* @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.
*
* @example
* //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.
* const positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),
* new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),
* new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];
* const cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);
*/
Ellipsoid.prototype.cartographicArrayToCartesianArray = function (
cartographics,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("cartographics", cartographics);
//>>includeEnd('debug')
const length = cartographics.length;
if (!defaultValue.defined(result)) {
result = new Array(length);
} else {
result.length = length;
}
for (let i = 0; i < length; i++) {
result[i] = this.cartographicToCartesian(cartographics[i], result[i]);
}
return result;
};
const cartesianToCartographicN = new Cartesian3();
const cartesianToCartographicP = new Cartesian3();
const cartesianToCartographicH = new Cartesian3();
/**
* Converts the provided cartesian to cartographic representation.
* The cartesian is undefined at the center of the ellipsoid.
*
* @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
*
* @example
* //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.
* const position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);
* const cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
*/
Ellipsoid.prototype.cartesianToCartographic = function (cartesian, result) {
//`cartesian is required.` is thrown from scaleToGeodeticSurface
const p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
if (!defaultValue.defined(p)) {
return undefined;
}
const n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);
const longitude = Math.atan2(n.y, n.x);
const latitude = Math.asin(n.z);
const height =
Math$1.CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
if (!defaultValue.defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
return result;
};
/**
* Converts the provided array of cartesians to an array of cartographics.
*
* @param {Cartesian3[]} cartesians An array of Cartesian positions.
* @param {Cartographic[]} [result] The object onto which to store the result.
* @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.
*
* @example
* //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.
* const positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),
* new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),
* new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]
* const cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);
*/
Ellipsoid.prototype.cartesianArrayToCartographicArray = function (
cartesians,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.defined("cartesians", cartesians);
//>>includeEnd('debug');
const length = cartesians.length;
if (!defaultValue.defined(result)) {
result = new Array(length);
} else {
result.length = length;
}
for (let i = 0; i < length; ++i) {
result[i] = this.cartesianToCartographic(cartesians[i], result[i]);
}
return result;
};
/**
* Scales the provided Cartesian position along the geodetic surface normal
* so that it is on the surface of this ellipsoid. If the position is
* at the center of the ellipsoid, this function returns undefined.
*
* @param {Cartesian3} cartesian The Cartesian position to scale.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
*/
Ellipsoid.prototype.scaleToGeodeticSurface = function (cartesian, result) {
return scaleToGeodeticSurface(
cartesian,
this._oneOverRadii,
this._oneOverRadiiSquared,
this._centerToleranceSquared,
result
);
};
/**
* Scales the provided Cartesian position along the geocentric surface normal
* so that it is on the surface of this ellipsoid.
*
* @param {Cartesian3} cartesian The Cartesian position to scale.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
*/
Ellipsoid.prototype.scaleToGeocentricSurface = function (cartesian, result) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("cartesian", cartesian);
//>>includeEnd('debug');
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
const positionX = cartesian.x;
const positionY = cartesian.y;
const positionZ = cartesian.z;
const oneOverRadiiSquared = this._oneOverRadiiSquared;
const beta =
1.0 /
Math.sqrt(
positionX * positionX * oneOverRadiiSquared.x +
positionY * positionY * oneOverRadiiSquared.y +
positionZ * positionZ * oneOverRadiiSquared.z
);
return Cartesian3.multiplyByScalar(cartesian, beta, result);
};
/**
* Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
* its components by the result of {@link Ellipsoid#oneOverRadii}.
*
* @param {Cartesian3} position The position to transform.
* @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
* return a new instance.
* @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the
* one passed as the result parameter if it is not undefined, or a new instance of it is.
*/
Ellipsoid.prototype.transformPositionToScaledSpace = function (
position,
result
) {
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
return Cartesian3.multiplyComponents(position, this._oneOverRadii, result);
};
/**
* Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
* its components by the result of {@link Ellipsoid#radii}.
*
* @param {Cartesian3} position The position to transform.
* @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
* return a new instance.
* @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the
* one passed as the result parameter if it is not undefined, or a new instance of it is.
*/
Ellipsoid.prototype.transformPositionFromScaledSpace = function (
position,
result
) {
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
return Cartesian3.multiplyComponents(position, this._radii, result);
};
/**
* Compares this Ellipsoid against the provided Ellipsoid componentwise and returns
* true
if they are equal, false
otherwise.
*
* @param {Ellipsoid} [right] The other Ellipsoid.
* @returns {boolean} true
if they are equal, false
otherwise.
*/
Ellipsoid.prototype.equals = function (right) {
return (
this === right ||
(defaultValue.defined(right) && Cartesian3.equals(this._radii, right._radii))
);
};
/**
* Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.
*
* @returns {string} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.
*/
Ellipsoid.prototype.toString = function () {
return this._radii.toString();
};
/**
* Computes a point which is the intersection of the surface normal with the z-axis.
*
* @param {Cartesian3} position the position. must be on the surface of the ellipsoid.
* @param {number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.
* In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.
* In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).
* Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2
* @param {Cartesian3} [result] The cartesian to which to copy the result, or undefined to create and
* return a new instance.
* @returns {Cartesian3 | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise
*
* @exception {DeveloperError} position is required.
* @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).
* @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.
*/
Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (
position,
buffer,
result
) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("position", position);
if (
!Math$1.CesiumMath.equalsEpsilon(
this._radii.x,
this._radii.y,
Math$1.CesiumMath.EPSILON15
)
) {
throw new Check.DeveloperError(
"Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)"
);
}
Check.Check.typeOf.number.greaterThan("Ellipsoid.radii.z", this._radii.z, 0);
//>>includeEnd('debug');
buffer = defaultValue.defaultValue(buffer, 0.0);
const squaredXOverSquaredZ = this._squaredXOverSquaredZ;
if (!defaultValue.defined(result)) {
result = new Cartesian3();
}
result.x = 0.0;
result.y = 0.0;
result.z = position.z * (1 - squaredXOverSquaredZ);
if (Math.abs(result.z) >= this._radii.z - buffer) {
return undefined;
}
return result;
};
const abscissas = [
0.14887433898163,
0.43339539412925,
0.67940956829902,
0.86506336668898,
0.97390652851717,
0.0,
];
const weights = [
0.29552422471475,
0.26926671930999,
0.21908636251598,
0.14945134915058,
0.066671344308684,
0.0,
];
/**
* Compute the 10th order Gauss-Legendre Quadrature of the given definite integral.
*
* @param {number} a The lower bound for the integration.
* @param {number} b The upper bound for the integration.
* @param {Ellipsoid~RealValuedScalarFunction} func The function to integrate.
* @returns {number} The value of the integral of the given function over the given domain.
*
* @private
*/
function gaussLegendreQuadrature(a, b, func) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.number("a", a);
Check.Check.typeOf.number("b", b);
Check.Check.typeOf.func("func", func);
//>>includeEnd('debug');
// The range is half of the normal range since the five weights add to one (ten weights add to two).
// The values of the abscissas are multiplied by two to account for this.
const xMean = 0.5 * (b + a);
const xRange = 0.5 * (b - a);
let sum = 0.0;
for (let i = 0; i < 5; i++) {
const dx = xRange * abscissas[i];
sum += weights[i] * (func(xMean + dx) + func(xMean - dx));
}
// Scale the sum to the range of x.
sum *= xRange;
return sum;
}
/**
* A real valued scalar function.
* @callback Ellipsoid~RealValuedScalarFunction
*
* @param {number} x The value used to evaluate the function.
* @returns {number} The value of the function at x.
*
* @private
*/
/**
* Computes an approximation of the surface area of a rectangle on the surface of an ellipsoid using
* Gauss-Legendre 10th order quadrature.
*
* @param {Rectangle} rectangle The rectangle used for computing the surface area.
* @returns {number} The approximate area of the rectangle on the surface of this ellipsoid.
*/
Ellipsoid.prototype.surfaceArea = function (rectangle) {
//>>includeStart('debug', pragmas.debug);
Check.Check.typeOf.object("rectangle", rectangle);
//>>includeEnd('debug');
const minLongitude = rectangle.west;
let maxLongitude = rectangle.east;
const minLatitude = rectangle.south;
const maxLatitude = rectangle.north;
while (maxLongitude < minLongitude) {
maxLongitude += Math$1.CesiumMath.TWO_PI;
}
const radiiSquared = this._radiiSquared;
const a2 = radiiSquared.x;
const b2 = radiiSquared.y;
const c2 = radiiSquared.z;
const a2b2 = a2 * b2;
return gaussLegendreQuadrature(minLatitude, maxLatitude, function (lat) {
// phi represents the angle measured from the north pole
// sin(phi) = sin(pi / 2 - lat) = cos(lat), cos(phi) is similar
const sinPhi = Math.cos(lat);
const cosPhi = Math.sin(lat);
return (
Math.cos(lat) *
gaussLegendreQuadrature(minLongitude, maxLongitude, function (lon) {
const cosTheta = Math.cos(lon);
const sinTheta = Math.sin(lon);
return Math.sqrt(
a2b2 * cosPhi * cosPhi +
c2 *
(b2 * cosTheta * cosTheta + a2 * sinTheta * sinTheta) *
sinPhi *
sinPhi
);
})
);
});
};
/**
* A 3x3 matrix, indexable as a column-major order array.
* Constructor parameters are in row-major order for code readability.
* @alias Matrix3
* @constructor
* @implements {ArrayLike
* Returns a diagonal matrix and unitary matrix such that:
* matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)
*
* The values along the diagonal of the diagonal matrix are the eigenvalues. The columns * of the unitary matrix are the corresponding eigenvectors. *
* * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric. * @param {object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result. * @returns {object} 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) */ Matrix3.computeEigenDecomposition = function (matrix, result) { //>>includeStart('debug', pragmas.debug); Check.Check.typeOf.object("matrix", matrix); //>>includeEnd('debug'); // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan, // section 8.4.3 The Classical Jacobi Algorithm const tolerance = Math$1.CesiumMath.EPSILON20; const maxSweeps = 10; let count = 0; let sweep = 0; if (!defaultValue.defined(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. */ Matrix3.abs = function (matrix, result) { //>>includeStart('debug', pragmas.debug); Check.Check.typeOf.object("matrix", matrix); Check.Check.typeOf.object("result", result); //>>includeEnd('debug'); 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. */ Matrix3.determinant = function (matrix) { //>>includeStart('debug', pragmas.debug); Check.Check.typeOf.object("matrix", matrix); //>>includeEnd('debug'); 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. */ Matrix3.inverse = function (matrix, result) { //>>includeStart('debug', pragmas.debug); Check.Check.typeOf.object("matrix", matrix); Check.Check.typeOf.object("result", result); //>>includeEnd('debug'); 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); //>>includeStart('debug', pragmas.debug); if (Math.abs(determinant) <= Math$1.CesiumMath.EPSILON15) { throw new Check.DeveloperError("matrix is not invertible"); } //>>includeEnd('debug'); 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.0 / determinant; return Matrix3.multiplyByScalar(result, scale, result); }; const scratchTransposeMatrix = new Matrix3(); /** * 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. */ Matrix3.inverseTranspose = function (matrix, result) { //>>includeStart('debug', pragmas.debug); Check.Check.typeOf.object("matrix", matrix); Check.Check.typeOf.object("result", result); //>>includeEnd('debug'); return Matrix3.inverse( Matrix3.transpose(matrix, scratchTransposeMatrix), result ); }; /** * Compares the provided matrices componentwise and returns *true
if they are equal, false
otherwise.
*
* @param {Matrix3} [left] The first matrix.
* @param {Matrix3} [right] The second matrix.
* @returns {boolean} true
if left and right are equal, false
otherwise.
*/
Matrix3.equals = function (left, right) {
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(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
* true
if they are within the provided epsilon,
* false
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} true
if left and right are within the provided epsilon, false
otherwise.
*/
Matrix3.equalsEpsilon = function (left, right, epsilon) {
epsilon = defaultValue.defaultValue(epsilon, 0);
return (
left === right ||
(defaultValue.defined(left) &&
defaultValue.defined(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)
);
};
/**
* An immutable Matrix3 instance initialized to the identity matrix.
*
* @type {Matrix3}
* @constant
*/
Matrix3.IDENTITY = Object.freeze(
new Matrix3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
);
/**
* An immutable Matrix3 instance initialized to the zero matrix.
*
* @type {Matrix3}
* @constant
*/
Matrix3.ZERO = Object.freeze(
new Matrix3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
);
/**
* The index into Matrix3 for column 0, row 0.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN0ROW0 = 0;
/**
* The index into Matrix3 for column 0, row 1.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN0ROW1 = 1;
/**
* The index into Matrix3 for column 0, row 2.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN0ROW2 = 2;
/**
* The index into Matrix3 for column 1, row 0.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN1ROW0 = 3;
/**
* The index into Matrix3 for column 1, row 1.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN1ROW1 = 4;
/**
* The index into Matrix3 for column 1, row 2.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN1ROW2 = 5;
/**
* The index into Matrix3 for column 2, row 0.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN2ROW0 = 6;
/**
* The index into Matrix3 for column 2, row 1.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN2ROW1 = 7;
/**
* The index into Matrix3 for column 2, row 2.
*
* @type {number}
* @constant
*/
Matrix3.COLUMN2ROW2 = 8;
Object.defineProperties(Matrix3.prototype, {
/**
* Gets the number of items in the collection.
* @memberof Matrix3.prototype
*
* @type {number}
*/
length: {
get: function () {
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.
*/
Matrix3.prototype.clone = function (result) {
return Matrix3.clone(this, result);
};
/**
* Compares this matrix to the provided matrix componentwise and returns
* true
if they are equal, false
otherwise.
*
* @param {Matrix3} [right] The right hand side matrix.
* @returns {boolean} true
if they are equal, false
otherwise.
*/
Matrix3.prototype.equals = function (right) {
return Matrix3.equals(this, right);
};
/**
* @private
*/
Matrix3.equalsArray = function (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
* true
if they are within the provided epsilon,
* false
otherwise.
*
* @param {Matrix3} [right] The right hand side matrix.
* @param {number} [epsilon=0] The epsilon to use for equality testing.
* @returns {boolean} true
if they are within the provided epsilon, false
otherwise.
*/
Matrix3.prototype.equalsEpsilon = function (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)'.
*/
Matrix3.prototype.toString = function () {
return (
`(${this[0]}, ${this[3]}, ${this[6]})\n` +
`(${this[1]}, ${this[4]}, ${this[7]})\n` +
`(${this[2]}, ${this[5]}, ${this[8]})`
);
};
exports.Cartesian3 = Cartesian3;
exports.Cartographic = Cartographic;
exports.Ellipsoid = Ellipsoid;
exports.Matrix3 = Matrix3;
}));