Skip to content

Instantly share code, notes, and snippets.

View begla's full-sized avatar

Benjamin Wrensch begla

View GitHub Profile
@begla
begla / gist:1019993
Created June 10, 2011 23:13
Linear, bilinear and trilinear interpolation
public static float lerp(float x, float x1, float x2, float q00, float q01) {
return ((x2 - x) / (x2 - x1)) * q00 + ((x - x1) / (x2 - x1)) * q01;
}
public static float biLerp(float x, float y, float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2) {
float r1 = lerp(x, x1, x2, q11, q21);
float r2 = lerp(x, x1, x2, q12, q22);
return lerp(y, y1, y2, r1, r2);
}