Documentation / @interstellar-tools/maps / viewshedGrid
Function: viewshedGrid()
ts
function viewshedGrid(
grid: GridInterface,
from: GridPositionInterface,
height: number,
radius: number
): GridInterface;Defined in: terrain/viewshed.ts:58
The viewshed of a point on an elevation grid: the ground that can be seen from height m above it, over the terrain between and round the body's curve.
Rays go from the point to every cell on the grid's edge, about half a cell a step, with heights from gridValueBetween, or the nearest cell's own next to a missing one. A cell is seen where no ground nearer on the ray rises above the line to it:
Where:
is the ground's height along the ray, and the ground's height at the point is height, andthe body's radius:is how far its curve drops the ground below the point's horizon
Units
- Heights, distances and the radius in m; the position in grid coordinates.
Notes
- The result is 1 where a cell is seen and 0 where it isn't, the same shape as the grid, with
NaNwhere it's missing. The point's own cell is seen. - A cell many rays cross is seen if any of them sees it, so the edges of hidden ground lean towards seen by up to a cell.
- Light bending in an atmosphere, which on Earth carries sight a little past the geometric horizon, is left out.
- From 2 m up, the horizon on flat ground is
away: 5.0 km on Earth, 3.7 km on Mars, 2.6 km on the Moon.
Parameters
| Parameter | Type | Description |
|---|---|---|
grid | GridInterface | Elevation grid, heights in m. |
from | GridPositionInterface | The point, in grid coordinates (on the grid; its nearest cell not missing). |
height | number | How far above the ground the eye is, in m (finite, ≥ 0). |
radius | number | The body's radius, in m (> 0, or Infinity for flat ground). |
Returns
A grid of the same shape: 1 seen, 0 hidden, NaN missing.
Throws
- If a size, cell size, the position or
heightis not finite, or a cell holds an infinite value. - If the grid's parts don't fit together, the point is off the grid or its nearest cell is missing,
heightis negative, orradiusis not > 0.
Example
ts
// What Perseverance's mast camera, 2 m up, could see from where it landed
const seen = viewshedGrid(grid, landing, 2, 3_396_190);