Skip to content

Instantly share code, notes, and snippets.

@chrisdel101
Last active March 11, 2023 20:08
Show Gist options
  • Save chrisdel101/b76cce4d57ee8fada168bb8350d1e6ed to your computer and use it in GitHub Desktop.
Save chrisdel101/b76cce4d57ee8fada168bb8350d1e6ed to your computer and use it in GitHub Desktop.
Tri linear interpolation
/*----------------TRILINEAR------------------------
*
y 110____11_____111
^ / | / |
| / | A /|
| / | / / |
| 010___|_01______011|
| | | | | |
| | 100_|___10__|_101
| | / M / | /
| | / | B | /
| | / |/ |/
| 000_____00____001
|
|-------------------------> x
/
/
/
/
/
z/
*/
PSEUDO CODE
// C_00 = C_000 (1 — xd) + C100 Xd
float i = floor(x);
float j = floor(y);
float k = floor(z);
// S = floor(x) - x
float dx = x - i;
float dy = y - j;
float dz = z - k;
//
// interpolate mid points of each edge - X axis
float C00 = (1-dx)CT[k][j][i] + (dx)CT[k][j][i+1]
float C01 = (1-dx)CT[k][j+1][i] + (dx)CT[k][j+1][i+1]
float C10 = (1-dx)CT[k+1][j][i] + (dx)CT[k+1][j][i+1]
float C11 = (1-dx)CT[k+1][j+1][i] + (dx)CT[k+1][j+][i+1]
// Y axis - use x vals already found
float A = (1-dy)C00 +_ (dy)C10
float B = (1-dy)C10 +_ (dy)C11
// Z axis - use x vals already found
float M = (1-dz)A + (dz)B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment