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.
Cartographic positions are represented as [longitude, latitude, height]. Longitude and latitude are in degrees, and height is in meters above the ellipsoid.
Use Ellipsoid.WGS84 for the standard Earth shape, construct three radii directly,
or use Ellipsoid.fromSpheroid to import two-axis geometry from a projection CRS.
Geometry is immutable, including the public radii, squared-radius and reciprocal
vectors. Construct a new Ellipsoid to change shape; mutating these vectors throws
instead of leaving prepared conversion caches inconsistent.
Surface projection selects a qualified nearest point rather than a radial
approximation. Unique near-cusp and boundary solutions have an exact-dyadic fallback. Ambiguous
interiors and inputs outside the qualified numerical range return
undefined without changing the supplied output. See the
nearest-point qualification and boundary policy.
Usageโ
Determine the Cartesian representation of a Cartographic position on a WGS84 ellipsoid.
import {Ellipsoid} from '@math.gl/geospatial/ellipsoid';
const cartographicPosition = [21, 78, 5000]; // [longitude, latitude, height]
const cartesianPosition = Ellipsoid.WGS84.cartographicToCartesian(cartographicPosition);
Determine the Cartographic representation of a Cartesian position on a WGS84 ellipsoid.
import {Ellipsoid} from '@math.gl/geospatial/ellipsoid';
const cartesianPosition = [17832.12, 83234.52, 952313.73];
const cartographicPosition = Ellipsoid.WGS84.cartesianToCartographic(cartesianPosition);
Get the transform from a local east-north-up frame at a point on the WGS84 ellipsoid to Earth's fixed frame.
import {Ellipsoid} from '@math.gl/geospatial/ellipsoid';
import {eastNorthUpToFixedFrame} from '@math.gl/geospatial/coordinates';
const cartesianOrigin = Ellipsoid.WGS84.cartographicToCartesian([21, 78, 0]);
const transformMatrix = eastNorthUpToFixedFrame(Ellipsoid.WGS84, cartesianOrigin);
See the accuracy and GeographicLib coverage audit for qualified domains, measured geodesic accuracy, and remaining capability gaps.
Projection interoperabilityโ
@math.gl/geospatial/projection uses spheres and oblate spheroids: its X/Y equatorial radii
are equal. Ellipsoid also supports three independent radii. The adapters exchange
only the common geometry; they do not transfer a datum, axis order, units or epoch.
import {Ellipsoid} from '@math.gl/geospatial/ellipsoid';
import {normalizeCRS} from '@math.gl/geospatial/projection-core';
const crs = normalizeCRS('+proj=longlat +ellps=GRS80');
const shape = Ellipsoid.fromSpheroid(crs.ellipsoid);
const parameters = shape.toSpheroid(); // {semiMajorAxis, semiMinorAxis}, in metres
Create/cache the adapter result during setup. Coordinate conversions still use the existing geospatial implementation. The projection module does not import geospatial at runtime. See coordinate-system concepts for the units and boundary conventions.
Static Fieldsโ
Ellipsoid.WGS84 : Ellipsoid (readonly)โ
An Ellipsoid instance initialized to the WGS84 standard.
Static Methodsโ
Ellipsoid.fromSpheroid(parameters: SpheroidParameters): Ellipsoidโ
Constructs radii [semiMajorAxis, semiMajorAxis, semiMinorAxis] from an owned
snapshot of the supplied axes. Accepts the geometry returned by
normalizeCRS(...).ellipsoid. Additional fields such as eccentricitySquared
are not imported; the axes determine the shape.
Throws if either axis is non-finite or non-positive, or the polar axis is larger than the equatorial axis. These checks apply to this adapter; the existing three-radius constructor retains its broader geometry support.
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.
toSpheroid(): SpheroidParametersโ
Returns a new frozen {semiMajorAxis, semiMinorAxis} snapshot in metres.
The snapshot remains independent of subsequent changes to the radii vector.
Throws for unequal X/Y radii, a prolate spheroid, non-finite axes or zero radii.
It never approximates a triaxial ellipsoid by discarding one radius.
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 as[longitude, latitude, height]. Longitude and latitude are in degrees, and height is in meters above the ellipsoid.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 position to cartographic representation. Latitude
retains precision near the poles. Returns undefined at the center, for non-finite
or unrepresentable inputs, or when its bounded inverse cannot converge; an existing
result is left unchanged. Sphere/oblate cartographic conversion uses the shared spheroid helpers, including the safeguarded nearest-normal interior inverse. Equatorial interiors with two equally near normals reject. Prolate/triaxial conversion retains the 64-update surface algorithm and its approximate near-center radial fallback. The separate scaleToGeodeticSurface method retains that three-radius behavior for all shapes. See ellipsoid accuracy and interior boundaries for independent references, branch selection and sampled accuracy limits.
cartesianThe Cartesian position to convert to cartographic representation.resultOptional object onto which to store the result.
Returns
- The modified result parameter, a new
Vector3instance if none was provided, orundefinedif the inverse is undefined or unsupported. A defined result contains[longitude, latitude, height], with longitude and latitude in degrees and height in meters above the ellipsoid.
eastNorthUpToFixedFrame(ellipsoid, origin : Number[3], result : Number[16]) : Matrix4 | Number[16]โ
Standalone export from @math.gl/geospatial and @math.gl/geospatial. Pass the ellipsoid as the first argument.
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 Cartesian position at the center of the local reference frame. -
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(ellipsoid, String firstAxis, secondAxis : String, thirdAxis : String | null, origin : Number[3] [, result : Number[16]]) : Matrix4 | Number[16]โ
Standalone export from @math.gl/geospatial and @math.gl/geospatial. Pass the ellipsoid as the first argument.
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 Cartesian position at the center 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.
Local-frame conventionsโ
eastNorthUpToFixedFrame and localFrameToFixedFrame use a Cartesian origin in
the ellipsoid's distance units; config._cartographicRadians does not affect them.
Their column-major matrix rotates local axes and translates by that origin.
Supply a reusable Matrix4 or number[] to avoid a new result per call.
Up is the normalized Cartesian origin divided by squared radii. On the surface
this is the surface normal; at height it can differ from the normal at the inverse
geodetic position used by deformation. Sphere/oblate frames share the original
@math.gl/core basis and
matrix functions while retaining this normal choice. Three-radius/prolate frames
retain the historical geometry path. At Cartesian poles (|x| and |y| โค 1e-14), east
is +Y and north/up use the sign of z. The historical center matrix is singular;
it is not a usable orthonormal frame.
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 WGS84 Cartesian coordinate for which 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 as[longitude, latitude, height]. Longitude and latitude are in degrees.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 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 onto the
ellipsoid. Returns undefined at the center, for non-finite or unrepresentable
inputs, singular updates, or after 64 unsuccessful Newton updates. Caller output
is unchanged on failure. Close to the center, the retained radial intersection is
an approximation rather than a normal footpoint.
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, orundefinedif the surface inverse is undefined or unsupported.
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.
See Attributions for the project-wide source inventory and acknowledgments.
P0 numeric and output contractsโ
The P0 qualification profile
details the supported samples and all public ownership, unit and boundary
contracts. Constructor axes must be finite and nonnegative; default/zero shapes
remain constructible but do not define a valid conversion surface. Normals and
radial surface projection now return undefined for zero/nonfinite rays without
modifying a supplied result. Forward conversion and normal/Z-axis intersection
also reject invalid numeric inputs before output writes.
Degree latitudes retain their complement near a pole, avoiding lost radians amplified by very flat shapes. Supplied result setters can invoke nested conversions without corrupting later output ordinates. The legacy local-frame pole neighborhood is bounded by shape scale in small units. These tighten previous failure/precision behavior; no runtime dependencies are added.
Metrics and geodesic areasโ
Use the separate EllipsoidMetrics class for revolution
ellipsoid metrics and auxiliary latitudes. GeodesicPolygon
and optional EllipsoidGeodesic edge areas support compensated polygon geometry.
These APIs use explicit degree units and retain the existing Cartesian API.
EllipsoidRhumb and RhumbPolygon provide constant-bearing paths and areas. GeodesicIntersections provides bounded searches with explicit completeness and segment statuses.
RhumbPath adds surface-distance sampling over the existing rhumb solver. Geographic seam splitters preserve declared edge semantics, attributes, holes and source provenance in a periodic longitude chart.