Skip to main content

Ellipsoid

From-v3.0

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โ€‹

From v5.0

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=0 The radius in the x direction.
  • y=0 The radius in the y direction.
  • z=0 The 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โ€‹

From v5.0

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.

  • right The other Ellipsoid. used.

Returns

  • true if they are equal, false otherwise.

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.

  • cartographic The cartographic position as [longitude, latitude, height]. Longitude and latitude are in degrees, and height is in meters above the ellipsoid.
  • result Optional object onto which to store the result.

Returns

  • The modified result parameter or a new Vector3 instance 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.

  • cartesian The Cartesian position to convert to cartographic representation.
  • result Optional object onto which to store the result.

Returns

  • The modified result parameter, a new Vector3 instance if none was provided, or undefined if 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 x axis points in the local east direction.

  • The y axis points in the local north direction.

  • The z axis points in the direction of the ellipsoid surface normal which passes through the position.

  • origin The Cartesian position at the center of the local reference frame.

  • result Optional object onto which to store the result.

Returns

  • The modified result parameter or a new Matrix4 instance if none was provided.

Notes

  • Calls localFrameToFixedFrame with east, north, up axis.

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.

  • firstAxis name of the first axis of the local reference frame. Must be 'east', 'north', 'up', 'west', 'south' or 'down'.
  • secondAxis name of the second axis of the local reference frame.
  • thirdAxis name 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.
  • origin The Cartesian position at the center of the local reference frame.
  • result Optional 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 result parameter or a new Matrix4 instance 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 Vector3 instance 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.

  • cartographic The cartographic position as [longitude, latitude, height]. Longitude and latitude are in degrees.
  • result Optional 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.

  • cartesian The Cartesian position for which to determine the surface normal.
  • result Optional object onto which to store the result.

Returns

  • The modified result parameter or a new Vector3 instance 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.

  • cartesian The Cartesian position to scale.
  • result Optional object onto which to store the result.

Returns

  • The modified result parameter, a new Vector3 instance if none was provided, or undefined if 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.

  • cartesian The Cartesian position to scale.
  • result Optional object onto which to store the result.

Returns

  • The modified result parameter or a new Vector3 instance 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.

  • position The position to transform.
  • result Optional array into which to copy the result.

Returns

  • 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.

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.

  • position The position to transform.
  • result Optional array to which to copy the result.

Returns

  • The position expressed in the unscaled space. The returned array is the one passed as the result parameter, or a new Vector3 instance.

getSurfaceNormalIntersectionWithZAxis(position, buffer, result) : | undefinedโ€‹

Computes a point which is the intersection of the surface normal with the z-axis.

  • position the position. must be on the surface of the ellipsoid.
  • buffer=0.0 A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.
  • result Optional array into which to copy the result.

Returns

  • The intersection point if it's inside the ellipsoid, undefined otherwise.

Throws

  • position is required.
  • Ellipsoid must 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.