Skip to content

Documentation / @interstellar-tools/maps / ellipseCells

Function: ellipseCells() ​

ts
function ellipseCells(
  grid: GridInterface,
  ellipse: GroundEllipseInterface
): GridInterface;

Defined in: terrain/ellipse.ts:159

A grid with only the cells whose centres lie inside an ellipse: the rest are missing. Pass it, or a grid of slopes cut the same way, to the terrain functions to ask about the ground inside: how steep it is, or how much of it a camera sees.

A cell is inside when

(x∥a)2+(x⊥b)2≤1

Where:

  • x∥ and x⊥ are its centre's distances from the ellipse's centre along its long and short axes, in m

Notes

  • The result is the same shape as the grid, with no noData: the cells outside, and missing cells inside, are NaN.
  • The grid is taken as flat with north up, as in ellipseOutline.

Parameters ​

ParameterTypeDescription
gridGridInterfaceThe grid, of heights or anything else.
ellipseGroundEllipseInterfaceThe ellipse.

Returns ​

GridInterface

The grid's values inside the ellipse, NaN outside.

Throws ​

  • If a size, cell size or the ellipse's centre, axes or azimuth is not finite, or a cell inside holds an infinite value.
  • If the grid's parts don't fit together, or an axis is not > 0.

Example ​

ts
// The share of a landing ellipse steeper than 15°
const slopes = ellipseCells(slopeGrid(grid), ellipse).values.filter(
  (s) => !Number.isNaN(s)
);
slopes.filter((s) => s > toRad(15)).length / slopes.length;

See ​

ellipseOutline