Trilinear interpolation is a method of multivariate interpolation on a 3-dimensional regular grid. It approximates the value of a function at an intermediate point
(x,y,z)
Trilinear interpolation is frequently used in numerical analysis, data analysis, and computer graphics.
D=1
D=2
D=3
2D=8
On a periodic and cubic lattice, let
xd
yd
zd
x
y
z
\begin{align} xd=
x-x0 | |
x1-x0 |
\\ yd=
y-y0 | |
y1-y0 |
\\ zd=
z-z0 | |
z1-z0 |
\end{align}
where
x0
x
x1
x
y0,y1,z0
z1
First we interpolate along
x
C0jk
C1jk
\begin{align} c00&=c000(1-xd)+c100xd\\ c01&=c001(1-xd)+c101xd\\ c10&=c010(1-xd)+c110xd\\ c11&=c011(1-xd)+c111xd \end{align}
Where
c000
(x0,y0,z0).
y
Ci0k
Ci1k
\begin{align} c0&=c00(1-yd)+c10yd\\ c1&=c01(1-yd)+c11yd \end{align}
Finally we interpolate these values along
z
c=c0(1-zd)+c1zd.
This gives us a predicted value for the point.
The result of trilinear interpolation is independent of the order of the interpolation steps along the three axes: any other order, for instance along
x
y
z
The above operations can be visualized as follows: First we find the eight corners of a cube that surround our point of interest. These corners have the values
c000
c100
c010
c110
c001
c101
c011
c111
Next, we perform linear interpolation between
c000
c100
c00
c001
c101
c01
c011
c111
c11
c010
c110
c10
Now we do interpolation between
c00
c10
c0
c01
c11
c1
c
c0
c1
In practice, a trilinear interpolation is identical to two bilinear interpolation combined with a linear interpolation:
c ≈ l\left(b(c000,c010,c100,c110),b(c001,c011,c101,c111)\right)
An alternative way to write the solution to the interpolation problem is
f(x,y,z) ≈ a0+a1x+a2y+a3z+a4xy+a5xz+a6yz+a7xyz
where the coefficients are found by solving the linear system
\begin{align} \begin{bmatrix} 1&x0&y0&z0&x0y0&x0z0&y0z0&x0y0z0\\ 1&x1&y0&z0&x1y0&x1z0&y0z0&x1y0z0\\ 1&x0&y1&z0&x0y1&x0z0&y1z0&x0y1z0\\ 1&x1&y1&z0&x1y1&x1z0&y1z0&x1y1z0\\ 1&x0&y0&z1&x0y0&x0z1&y0z1&x0y0z1\\ 1&x1&y0&z1&x1y0&x1z1&y0z1&x1y0z1\\ 1&x0&y1&z1&x0y1&x0z1&y1z1&x0y1z1\\ 1&x1&y1&z1&x1y1&x1z1&y1z1&x1y1z1\end{bmatrix}\begin{bmatrix} a0\ a1\ a2\ a3\ a4\ a5\ a6\ a7 \end{bmatrix}=\begin{bmatrix} c000\ c100\ c010\ c110\ c001\ c101\ c011\ c111\end{bmatrix}, \end{align}
yielding the result
\begin{align} a0={} &
-c000x1y1z1+c001x1y1z0+c010x1y0z1-c011x1y0z0 | |
(x0-x1)(y0-y1)(z0-z1) |
+{}\\ &
c100x0y1z1-c101x0y1z0-c110x0y0z1+c111x0y0z0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a1={} &
c000y1z1-c001y1z0-c010y0z1+c011y0z0 | |
(x0-x1)(y0-y1)(z0-z1) |
+{}\\ &
-c100y1z1+c101y1z0+c110y0z1-c111y0z0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a2={} &
c000x1z1-c001x1z0-c010x1z1+c011x1z0 | |
(x0-x1)(y0-y1)(z0-z1) |
+{}\\ &
-c100x0z1+c101x0z0+c110x0z1-c111x0z0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a3={} &
c000x1y1-c001x1y1-c010x1y0+c011x1y0 | |
(x0-x1)(y0-y1)(z0-z1) |
+{}\\ &
-c100x0y1+c101x0y1+c110x0y0-c111x0y0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a4={} &
-c000z1+c001z0+c010z1-c011z0+c100z1-c101z0-c110z1+c111z0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a5= &
-c000y1+c001y1+c010y0-c011y0+c100y1-c101y1-c110y0+c111y0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a6={} &
-c000x1+c001x1+c010x1-c011x1+c100x0-c101x0-c110x0+c111x0 | |
(x0-x1)(y0-y1)(z0-z1) |
,\\[4pt] a7={} &
c000-c001-c010+c011-c100+c101+c110-c111 | |
(x0-x1)(y0-y1)(z0-z1) |
. \end{align}