Skip to content

Instantly share code, notes, and snippets.

@tomoima525
Forked from botagar/blerp.js
Created November 8, 2022 18:00
Show Gist options
  • Save tomoima525/89bd93fb71830836e57f3fdd1ee0c0f4 to your computer and use it in GitHub Desktop.
Save tomoima525/89bd93fb71830836e57f3fdd1ee0c0f4 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