Trilinear interpolation

From HandWiki
Short description: Method of multivariate interpolation on a 3-dimensional regular grid

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 [math]\displaystyle{ (x, y, z) }[/math] 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

Trilinear interpolation is the extension of linear interpolation, which operates in spaces with dimension [math]\displaystyle{ D = 1 }[/math], and bilinear interpolation, which operates with dimension [math]\displaystyle{ D = 2 }[/math], to dimension [math]\displaystyle{ D = 3 }[/math]. These interpolation schemes all use polynomials of order 1, giving an accuracy of order 2, and it requires [math]\displaystyle{ 2^D = 8 }[/math] 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

Eight corner points on a cube surrounding the interpolation point C
Depiction of 3D interpolation
A geometric visualisation of trilinear interpolation. The product of the value at the desired point and the entire volume is equal to the sum of the products of the value at each corner and the partial volume diagonally opposite the corner.

On a periodic and cubic lattice, let [math]\displaystyle{ x_\text{d} }[/math], [math]\displaystyle{ y_\text{d} }[/math], and [math]\displaystyle{ z_\text{d} }[/math] be the differences between each of [math]\displaystyle{ x }[/math], [math]\displaystyle{ y }[/math], [math]\displaystyle{ z }[/math] and the smaller coordinate related, that is:

[math]\displaystyle{ \begin{align} x_\text{d} = \frac{x - x_0}{x_1 - x_0} \\ y_\text{d} = \frac{y - y_0}{y_1 - y_0} \\ z_\text{d} = \frac{z - z_0}{z_1 - z_0} \end{align} }[/math]

where [math]\displaystyle{ x_0 }[/math] indicates the lattice point below [math]\displaystyle{ x }[/math], and [math]\displaystyle{ x_1 }[/math] indicates the lattice point above [math]\displaystyle{ x }[/math] and similarly for [math]\displaystyle{ y_0, y_1, z_0 }[/math] and [math]\displaystyle{ z_1 }[/math].

First we interpolate along [math]\displaystyle{ x }[/math] (imagine we are "pushing" the face of the cube defined by [math]\displaystyle{ C_{0jk} }[/math] to the opposing face, defined by [math]\displaystyle{ C_{1jk} }[/math]), giving:

[math]\displaystyle{ \begin{align} c_{00} &= c_{000} (1 - x_\text{d}) + c_{100} x_\text{d} \\ c_{01} &= c_{001} (1 - x_\text{d}) + c_{101} x_\text{d} \\ c_{10} &= c_{010} (1 - x_\text{d}) + c_{110} x_\text{d} \\ c_{11} &= c_{011} (1 - x_\text{d}) + c_{111} x_\text{d} \end{align} }[/math]

Where [math]\displaystyle{ c_{000} }[/math] means the function value of [math]\displaystyle{ (x_0, y_0, z_0). }[/math] Then we interpolate these values (along [math]\displaystyle{ y }[/math], "pushing" from [math]\displaystyle{ C_{i0k} }[/math] to [math]\displaystyle{ C_{i1k} }[/math]), giving:

[math]\displaystyle{ \begin{align} c_0 &= c_{00}(1 - y_\text{d}) + c_{10}y_\text{d} \\ c_1 &= c_{01}(1 - y_\text{d}) + c_{11}y_\text{d} \end{align} }[/math]

Finally we interpolate these values along [math]\displaystyle{ z }[/math] (walking through a line):

[math]\displaystyle{ c = c_0(1 - z_\text{d}) + c_1z_\text{d} . }[/math]

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 [math]\displaystyle{ x }[/math], then along [math]\displaystyle{ y }[/math], and finally along [math]\displaystyle{ z }[/math], 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 [math]\displaystyle{ c_{000} }[/math], [math]\displaystyle{ c_{100} }[/math], [math]\displaystyle{ c_{010} }[/math], [math]\displaystyle{ c_{110} }[/math], [math]\displaystyle{ c_{001} }[/math], [math]\displaystyle{ c_{101} }[/math], [math]\displaystyle{ c_{011} }[/math], [math]\displaystyle{ c_{111} }[/math].

Next, we perform linear interpolation between [math]\displaystyle{ c_{000} }[/math] and [math]\displaystyle{ c_{100} }[/math] to find [math]\displaystyle{ c_{00} }[/math], [math]\displaystyle{ c_{001} }[/math] and [math]\displaystyle{ c_{101} }[/math] to find [math]\displaystyle{ c_{01} }[/math], [math]\displaystyle{ c_{011} }[/math] and [math]\displaystyle{ c_{111} }[/math] to find [math]\displaystyle{ c_{11} }[/math], [math]\displaystyle{ c_{010} }[/math] and [math]\displaystyle{ c_{110} }[/math] to find [math]\displaystyle{ c_{10} }[/math].

Now we do interpolation between [math]\displaystyle{ c_{00} }[/math] and [math]\displaystyle{ c_{10} }[/math] to find [math]\displaystyle{ c_{0} }[/math], [math]\displaystyle{ c_{01} }[/math] and [math]\displaystyle{ c_{11} }[/math] to find [math]\displaystyle{ c_{1} }[/math]. Finally, we calculate the value [math]\displaystyle{ c }[/math] via linear interpolation of [math]\displaystyle{ c_{0} }[/math] and [math]\displaystyle{ c_{1} }[/math]

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

[math]\displaystyle{ c \approx l\left( b(c_{000}, c_{010}, c_{100}, c_{110}),\, b(c_{001}, c_{011}, c_{101}, c_{111})\right) }[/math]

Alternative algorithm

An alternative way to write the solution to the interpolation problem is

[math]\displaystyle{ f(x, y, z) \approx a_0 + a_1 x + a_2 y + a_3 z + a_4 x y + a_5 x z + a_6 y z + a_7 x y z }[/math]

where the coefficients are found by solving the linear system

[math]\displaystyle{ \begin{align} \begin{bmatrix} 1 & x_0 & y_0 & z_0 & x_0 y_0 & x_0 z_0 & y_0 z_0 & x_0 y_0 z_0 \\ 1 & x_1 & y_0 & z_0 & x_1 y_0 & x_1 z_0 & y_0 z_0 & x_1 y_0 z_0 \\ 1 & x_0 & y_1 & z_0 & x_0 y_1 & x_0 z_0 & y_1 z_0 & x_0 y_1 z_0 \\ 1 & x_1 & y_1 & z_0 & x_1 y_1 & x_1 z_0 & y_1 z_0 & x_1 y_1 z_0 \\ 1 & x_0 & y_0 & z_1 & x_0 y_0 & x_0 z_1 & y_0 z_1 & x_0 y_0 z_1 \\ 1 & x_1 & y_0 & z_1 & x_1 y_0 & x_1 z_1 & y_0 z_1 & x_1 y_0 z_1 \\ 1 & x_0 & y_1 & z_1 & x_0 y_1 & x_0 z_1 & y_1 z_1 & x_0 y_1 z_1 \\ 1 & x_1 & y_1 & z_1 & x_1 y_1 & x_1 z_1 & y_1 z_1 & x_1 y_1 z_1 \end{bmatrix}\begin{bmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \\ a_4 \\ a_5 \\ a_6 \\ a_7 \end{bmatrix} = \begin{bmatrix} c_{000} \\ c_{100} \\ c_{010} \\ c_{110} \\ c_{001} \\ c_{101} \\ c_{011} \\ c_{111} \end{bmatrix}, \end{align} }[/math]

yielding the result

[math]\displaystyle{ \begin{align} a_0 ={} &\frac{-c_{000} x_1 y_1 z_1 + c_{001} x_1 y_1 z_0 + c_{010} x_1 y_0 z_1 - c_{011} x_1 y_0 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)} +{} \\ &\frac{ c_{100} x_0 y_1 z_1 - c_{101} x_0 y_1 z_0 - c_{110} x_0 y_0 z_1 + c_{111} x_0 y_0 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_1 ={} &\frac{ c_{000} y_1 z_1 - c_{001} y_1 z_0 - c_{010} y_0 z_1 + c_{011} y_0 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)} +{} \\ &\frac{-c_{100} y_1 z_1 + c_{101} y_1 z_0 + c_{110} y_0 z_1 - c_{111} y_0 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_2 ={} &\frac{ c_{000} x_1 z_1 - c_{001} x_1 z_0 - c_{010} x_1 z_1 + c_{011} x_1 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)} +{} \\ &\frac{-c_{100} x_0 z_1 + c_{101} x_0 z_0 + c_{110} x_0 z_1 - c_{111} x_0 z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_3 ={} &\frac{ c_{000} x_1 y_1 - c_{001} x_1 y_1 - c_{010} x_1 y_0 + c_{011} x_1 y_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)} +{} \\ &\frac{-c_{100} x_0 y_1 + c_{101} x_0 y_1 + c_{110} x_0 y_0 - c_{111} x_0 y_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_4 ={} &\frac{-c_{000} z_1 + c_{001} z_0 + c_{010} z_1 - c_{011} z_0 + c_{100} z_1 - c_{101} z_0 - c_{110} z_1 + c_{111} z_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_5 = &\frac{-c_{000} y_1 + c_{001} y_1 + c_{010} y_0 - c_{011} y_0 + c_{100} y_1 - c_{101} y_1 - c_{110} y_0 + c_{111} y_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_6 ={} &\frac{-c_{000} x_1 + c_{001} x_1 + c_{010} x_1 - c_{011} x_1 + c_{100} x_0 - c_{101} x_0 - c_{110} x_0 + c_{111} x_0}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}, \\[4pt] a_7 ={} &\frac{ c_{000} - c_{001} - c_{010} + c_{011} - c_{100} + c_{101} + c_{110} - c_{111}}{(x_0 - x_1) (y_0 - y_1) (z_0 - z_1)}. \end{align} }[/math]

See also

External links

  • pseudo-code from NASA, describes an iterative inverse trilinear interpolation (given the vertices and the value of C find Xd, Yd and Zd).
  • Paul Bourke, Interpolation methods, 1999. Contains a very clever and simple method to find trilinear interpolation that is based on binary logic and can be extended to any dimension (Tetralinear, Pentalinear, ...).
  • Kenwright, Free-Form Tetrahedron Deformation. International Symposium on Visual Computing. Springer International Publishing, 2015 [1].