Skip to content

Documentation / @interstellar-tools/maps / profile

Function: profile() ​

ts
function profile(
  grid: GridInterface,
  from: GridPositionInterface,
  to: GridPositionInterface
): ProfilePointInterface[];

Defined in: terrain/profile.ts:78

The height profile along a straight line on an elevation grid: heights about a cell apart, from gridValueBetween.

n=max(1,⌈Δr2+Δc2⌉),dk=kn(Δrsy)2+(Δcsx)2

Where:

  • Δr and Δc are the rows and columns from start to end, and sx and sy the cell size
  • n is the number of steps: about one a cell; dk is sample k's distance along the line

Units

  • Positions in grid coordinates; distances and heights in m.

Notes

  • The first sample is at the start and the last at the end, so there are n+1.
  • The line is straight on the grid, a rhumb line on its map: over a few kilometres, the same as on the ground.
  • The building block for line of sight, clearance under a flight path and the cost of a route.

Parameters ​

ParameterTypeDescription
gridGridInterfaceElevation grid, heights in m.
fromGridPositionInterfaceWhere it starts, in grid coordinates (on the grid).
toGridPositionInterfaceWhere it ends, in grid coordinates (on the grid).

Returns ​

ProfilePointInterface[]

The samples, from the start.

Throws ​

  • If a size, cell size or position is not finite.
  • If the grid's parts don't fit together, or a position is off the grid.

Example ​

ts
// Across a crater, west to east through its middle
const points = profile(
  grid,
  { row: 128, column: 0 },
  { row: 128, column: 255 }
);
profileStats(points).lowest; // the crater's floor, in m

See ​