public DReal Height(DVector3 position) { var ix = (int)position.x; var iz = (int)position.z; // Corner heights. var ha = RawHeight(ix, iz); var hb = RawHeight(ix + 1, iz); var hc = RawHeight(ix, iz + 1); var hd = RawHeight(ix + 1, iz + 1); // Interpolation offsets. var tx = position.x - ix; var tz = position.z - iz; return(DReal.BilinearLerp(ha, hb, hc, hd, tx, tz)); }