Skip to content

Instantly share code, notes, and snippets.

@botagar
Created May 5, 2020 23:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save botagar/5d628f06545d5427fe4a694d1a02467e to your computer and use it in GitHub Desktop.
Save botagar/5d628f06545d5427fe4a694d1a02467e to your computer and use it in GitHub Desktop.
Javascript implementation of Bilinear Interpolation
Math.blerp = function (values, x1, y1, x2, y2, x, y) {
let q11 = (((x2 - x) * (y2 - y)) / ((x2 - x1) * (y2 - y1))) * values[x1][y1]
let q21 = (((x - x1) * (y2 - y)) / ((x2 - x1) * (y2 - y1))) * values[x2][y1]
let q12 = (((x2 - x) * (y - y1)) / ((x2 - x1) * (y2 - y1))) * values[x1][y2]
let q22 = (((x - x1) * (y - y1)) / ((x2 - x1) * (y2 - y1))) * values[x2][y2]
return q11 + q21 + q12 + q22
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment