Skip to content

Instantly share code, notes, and snippets.

@ssube
Created September 8, 2014 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssube/e4dcd755a2ce70a0734e to your computer and use it in GitHub Desktop.
Save ssube/e4dcd755a2ce70a0734e to your computer and use it in GitHub Desktop.
to find the linearly interpolated value of (x + 0.4, y + 0.7)
given the values at (x, y), (x, y+1), (x+1, y), and (x+1, y+1)
let x1 = val(x, y) * 0.4 + (val(x, y+1) * 0.6)
let x2 = val(x+1, y) * 0.4 + (val(x+1, y+1) * 0.6)
the final value is (x1 * 0.7 + (x2 * 0.3))
generalized:
to find the linearly interpolated value of (x + dX, y + dY)
given the values at (x, y), (x, y+1), (x+1, y), and (x+1, y+1)
let x1 = val(x, y) * dX + (val(x, y+1) * (1-dX))
let x2 = val(x+1, y) * dX + (val(x+1, y+1) * (1-dX))
the final value is (x1 * dY + (x2 * (1-dY)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment