Trilinear interpolation explained

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)

within the local axial rectangular prism linearly, using function data on the lattice points. For an arbitrary, unstructured mesh (as used in finite element analysis), other methods of interpolation must be used; if all the mesh elements are tetrahedra (3D simplices), then barycentric coordinates provide a straightforward procedure.

Trilinear interpolation is frequently used in numerical analysis, data analysis, and computer graphics.

Compared to linear and bilinear interpolation

D=1

, and bilinear interpolation, which operates with dimension

D=2

, to dimension

D=3

. These interpolation schemes all use polynomials of order 1, giving an accuracy of order 2, and it requires

2D=8

adjacent pre-defined values surrounding the interpolation point. There are several ways to arrive at trilinear interpolation, which is equivalent to 3-dimensional tensor B-spline interpolation of order 1, and the trilinear interpolation operator is also a tensor product of 3 linear interpolation operators.

Method

On a periodic and cubic lattice, let

xd

,

yd

, and

zd

be the differences between each of

x

,

y

,

z

and the smaller coordinate related, that is:

\begin{align} xd=

x-x0
x1-x0

\\ yd=

y-y0
y1-y0

\\ zd=

z-z0
z1-z0

\end{align}

where

x0

indicates the lattice point below

x

, and

x1

indicates the lattice point above

x

and similarly for

y0,y1,z0

and

z1

.

First we interpolate along

x

(imagine we are "pushing" the face of the cube defined by

C0jk

to the opposing face, defined by

C1jk

), giving:

\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

means the function value of

(x0,y0,z0).

Then we interpolate these values (along

y

, "pushing" from

Ci0k

to

Ci1k

), giving:

\begin{align} c0&=c00(1-yd)+c10yd\\ c1&=c01(1-yd)+c11yd \end{align}

Finally we interpolate these values along

z

(walking through a line):

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

, then along

y

, and finally along

z

, produces the same value.

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

and

c100

to find

c00

,

c001

and

c101

to find

c01

,

c011

and

c111

to find

c11

,

c010

and

c110

to find

c10

.

Now we do interpolation between

c00

and

c10

to find

c0

,

c01

and

c11

to find

c1

. Finally, we calculate the value

c

via linear interpolation of

c0

and

c1

In practice, a trilinear interpolation is identical to two bilinear interpolation combined with a linear interpolation:

cl\left(b(c000,c010,c100,c110),b(c001,c011,c101,c111)\right)

Alternative algorithm

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}

See also

External links