Last active
March 11, 2023 20:08
-
-
Save chrisdel101/b76cce4d57ee8fada168bb8350d1e6ed to your computer and use it in GitHub Desktop.
Tri linear interpolation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------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