Skip to content

Documentation / @interstellar-tools/maps / slopeAt

Function: slopeAt() ​

ts
function slopeAt(grid: GridInterface, row: number, column: number): Radians;

Defined in: terrain/slope.ts:52

Compute the slope of an elevation grid at a cell: how steep the terrain is.

slope=arctan⁡(∂z∂x)2+(∂z∂y)2

with the gradient from Horn's method, gradientAt.

Units

  • Input: heights and the cell size in m.
  • Output: slope in radians, in [0, π/2): 0 is flat.

Notes

  • The slope over the cell's 3 × 3 neighbourhood, so over a patch three cells across: a 1 m grid sees boulders, a 100 m grid only hills. Landing hazards depend on the scale of the lander.
  • NaN on the grid's edge and next to a missing cell.
  • isStableLanding takes a slope in radians directly.

Parameters ​

ParameterTypeDescription
gridGridInterfaceElevation grid, heights in m.
rownumberRow index, 0 at the north edge (an integer in [0, rows)).
columnnumberColumn index, 0 at the west edge (an integer in [0, columns)).

Returns ​

Radians

The slope in radians, or NaN where it can't be computed.

Throws ​

If row or column is not an integer inside the grid.

Example ​

ts
// Rising 1 m every 10 m to the east
const grid = createGrid({
  rows: 3,
  columns: 3,
  values: [0, 1, 2, 0, 1, 2, 0, 1, 2],
  cellSize: { x: 10, y: 10 }
});

slopeAt(grid, 1, 1); // atan(0.1) ≈ 5.7°

See ​