Finding the height of a wave at a point is actually pretty complicated. Since the equation for the waves moves each point on three axis, it takes more than just solving for the inverse.

I use an iterative technique to solve a system of equations that yields the Y-coordinate elevation at a given (X,Z) coordinate.

For those interested in the math:

Suppose we use the equation *f*(x,z) = (x’, y’, z’) to generate our ocean. It maps a coordinate on a plane to a coordinate on the surface of a wave.

We want to find the height at a given point. That is, we want to find the y’ value for a given the (x’, z’) coordinate. Unfortunately, our equation can’t give us that explicitly. We can’t simply solve our equation for y’ because the result gives us infinitely many solutions. We have an equation with five variables, we know two, x’ and z’, and we’re trying to solve for one, y’. It doesn’t work.

Fortunately, each of our infinitely many solutions are at a local maximum near (x, z), because *f*(x, z) only displaces (x’, z’) by a small amount (*i.e. the waves only move by a small amount horizontally*). So, using an iterative gradient descent algorithm, we can find the values of y’, x, and z that satisfy *f* near (x’, z’).

We can do this by starting with a guess. Say, x

_{1}=x' and z

_{1}=z' as our first guess. Then plug that guess into

*f* to get a new (x", y", z") coordinate. Given how that coordinate compares to our initial guess, we can make a new better guess, (x

_{2}, z

_{2}), and plug it in again. Keep doing this until the outputs (x", z") are very close to the original (x', z'). The resulting y" in the vector is the elevation at the point (x', z'). In other words,

*f*(x',z') = (x", y", z").