Ellipsoid
A quadratic surface defined in Cartesian coordinates by the equation (x / a)^2 + (y / b)^2 + (z / c)^2 = 1. Primarily used to represent the shape of planetary bodies.
The main use of this class is to convert between the "cartesian" and "cartographic" coordinate systems.
Rather than constructing this object directly, one of the provided constants is used.
Usage
Determine the Cartesian representation of a Cartographic position on a WGS84 ellipsoid.
import {toRadians} from '@math.gl/core';
import {Ellipsoid} from '@math.gl/geospatial';
const cartographicPosition = [toRadians(21), toRadians(78), 5000];
const cartesianPosition = Ellipsoid.WGS84.cartographicToCartesian(cartographicPosition);
Determine the Cartographic representation of a Cartesian position on a WGS84 ellipsoid.
import {Ellipsoid} from '@math.gl/geospatial';
const cartesianPosition = [17832.12, 83234.52, 952313.73];
const cartographicPosition = Ellipsoid.WGS84.cartesianToCartographic(cartesianPosition);
Get the transform from local east-north-up at cartographic (0.0, 0.0) to Earth's fixed frame.
import {Ellipsoid} from '@math.gl/geospatial';
const transformMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame([0, 0, 0]);
Static Fields
Ellipsoid.WGS84 : Ellipsoid (readonly)
An Ellipsoid instance initialized to the WGS84 standard.
Members
radii : Vector3 (readonly)
Gets the radii of the ellipsoid.
radiiSquared : Vector3 (readonly)
Gets the squared radii of the ellipsoid.
radiiToTheFourth : Vector3 (readonly)
Gets the radii of the ellipsoid raise to the fourth power.
oneOverRadii : Vector3 (readonly)
Gets one over the radii of the ellipsoid.
oneOverRadiiSquared : Vector3 (readonly)
Gets one over the squared radii of the ellipsoid.
minimumRadius : Number (readonly)
Gets the minimum radius of the ellipsoid.
maximumRadius : Number
Gets the maximum radius of the ellipsoid.
Methods
constructor(x : Number, y : Number, z : Number)
x=0The radius in the x direction.y=0The radius in the y direction.z=0The radius in the z direction.
Throws
- All radii components must be greater than or equal to zero.
clone() : Ellipsoid
Duplicates an Ellipsoid instance.
- result?: Ellipsoid - Optional object onto which to store the result, or undefined if a new instance should be created.
Returns
- The cloned
Ellipsoid.
equals(right : Ellipsoid) : Boolean
Compares this Ellipsoid against the provided Ellipsoid componentwise.
rightThe other Ellipsoid. used.
Returns
trueif they are equal,falseotherwise.
toString() : String
Creates a string representing this Ellipsoid in the format used '[radii.x, radii.y, radii.z].
Returns
- A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.
cartographicToCartesian(cartographic : Number[3], result : Number[3]]) : Vector3 | Number[3]
Converts the provided cartographic to Cartesian representation.
cartographicThe cartographic position.resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newVector3instance if none was provided.
cartesianToCartographic(cartesian : Number[3], result : Number[3]]) : Vector3 | Number[3] | undefined
Converts the provided cartesian to cartographic representation. The cartesian is undefined at the center of the ellipsoid.
cartesianThe Cartesian position to convert to cartographic representation.resultOptional object onto which to store the result.
Returns
- The modified result parameter, new
Vector3instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
eastNorthUpToFixedFrame(origin : Number[3], ellpsoid : Ellipsoid, result : Number[16]) : Matrix4 | Number[16]
Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes centered at the provided origin to the provided ellipsoid's fixed reference frame.
The local axes are defined as:
-
The
xaxis points in the local east direction. -
The
yaxis points in the local north direction. -
The
zaxis points in the direction of the ellipsoid surface normal which passes through the position. -
originThe center point of the local reference frame. -
ellipsoid=Ellipsoid.WGS84The ellipsoid whose fixed frame is used in the transformation. -
resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newMatrix4instance if none was provided.
Notes
- Calls
localFrameToFixedFramewitheast,north,upaxis.
localFrameToFixedFrame(String firstAxis, secondAxis : String, thirdAxis : String | null, origin : Number[3] [, result : Number[16]]) : Matrix4 | Number[16]
Computes a 4x4 transformation matrix from a reference frame centered at the provided origin to the ellipsoid's fixed reference frame.
firstAxisname of the first axis of the local reference frame. Must be 'east', 'north', 'up', 'west', 'south' or 'down'.secondAxisname of the second axis of the local reference frame.thirdAxisname of the third axis of the local reference frame. Can be omitted as it is implied by the cross product of the first two axis.originThe center point of the local reference frame.resultOptional object onto which to store the result.
Returns
- A 4x4 transformation matrix from a reference frame, with first axis and second axis compliant with the parameters, in the modified
resultparameter or a newMatrix4instance if none was provided.
geocentricSurfaceNormal(cartesian : Number[3], result : Number[3]]) : Vector3 | Number[3]
Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.
cartesian- The WSG84 cartesian coordinate for which to to determine the geocentric normal.result- Optional object onto which to store the result.
Returns
- The modified result parameter or a new
Vector3instance if none was provided.
geodeticSurfaceNormalCartographic(cartographic : Number[3], result : Number[3]]) : Vector3 | Number[3]
Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
cartographicThe cartographic position for which to to determine the geodetic normal.resultOptional object onto which to store the result.
Returns
The modified result parameter or a new Vector3 instance if none was provided.
geodeticSurfaceNormal(cartesian : Number[3], result : Number[3]]) : Vector3 | Number[3]
Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
cartesianThe Cartesian position for which to to determine the surface normal.resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newVector3instance if none was provided.
scaleToGeodeticSurface(cartesian : Number[3], result : Number[3]]) : Vector3 | Number[3] | undefined
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.
cartesianThe Cartesian position to scale.resultOptional object onto which to store the result.
Returns
- The modified result parameter, a new
Vector3instance if none was provided, or undefined if the position is at the center.
scaleToGeocentricSurface(cartesian : Number[3], result : Number[3]]) : Vector3 | Number[3]
Scales the provided Cartesian position along the geocentric surface normal so that it is on the surface of this ellipsoid.
cartesianThe Cartesian position to scale.resultOptional object onto which to store the result.
Returns
- The modified
resultparameter or a newVector3instance if none was provided.
transformPositionToScaledSpace(position : Number[3], result : Number[3]]) : Vector3 | Number[3]
Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying its components by the result of Ellipsoid.oneOverRadii.
positionThe position to transform.resultOptional array into which to copy the result.
Returns
- The position expressed in the scaled space. The returned instance is the one passed as the
resultparameter if it is not undefined, or a new instance of it is.
transformPositionFromScaledSpace(position : Number[3], result : Number[3]]) : Vector3 | Number[3]
Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying its components by the result of Ellipsoid.radii.
positionThe position to transform.resultOptional array to which to copy the result.
Returns
- The position expressed in the unscaled space. The returned array is the one passed as the
resultparameter, or a newVector3instance.
getSurfaceNormalIntersectionWithZAxis(position, buffer, result) : | undefined
Computes a point which is the intersection of the surface normal with the z-axis.
positionthe position. must be on the surface of the ellipsoid.buffer=0.0A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.resultOptional array into which to copy the result.
Returns
- The intersection point if it's inside the ellipsoid,
undefinedotherwise.
Throws
positionis required.Ellipsoidmust be an ellipsoid of revolution (radii.x == radii.y).- Ellipsoid.radii.z must be greater than 0.
Notes:
- 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
Attribution
This class was ported from Cesium under the Apache 2 License.