Workshop › Lunar Lander › Step 4 of 31
To know when the lander touches the ground, we need the ground's height at any x, not only at the points. Between two points the ground is a straight line, so we blend between their heights.
```js
// The ground between two points is a straight line: find where x is along it.
function groundY(x) {
const i = Math.max(0, Math.min(ground.length - 2, Math.floor(x / STEP)))
const t = (x - i * STEP) / STEP
return ground[i] + (ground[i + 1] - ground[i]) * t
}
```i is the point on the left of x, kept between 0 and the second-to-last point so i + 1 always exists.t is how far x is from point i to point i + 1: 0 at the left one, 1 at the right one.t of the way to the right height.Leave an empty line under makeGround and write groundY with its comment.
Skills: Velocity and gravity, Functions