Trilinear interpolation
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 formula_1 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 formula_2, and bilinear interpolation, which operates with dimension formula_3, to dimension formula_4. These interpolation schemes all use polynomials of order 1, giving an accuracy of order 2, and it requires formula_5 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 formula_6, formula_7, and formula_8 be the differences  between each of formula_9, formula_10, formula_11 and the smaller coordinate related, that is: where formula_13 indicates the lattice point below formula_14, and formula_15 indicates the lattice point above formula_14 and similarly for formula_17 and formula_18. First we interpolate along formula_9 (imagine we are "pushing" the face of the cube defined by formula_20 to the opposing face, defined by formula_21), giving: Where formula_23 means the function value of formula_24 Then we interpolate these values (along formula_10, "pushing" from formula_26 to formula_27), giving: Finally we interpolate these values along formula_11 (walking through a line): 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 formula_9, then along formula_10, and finally along formula_11, 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 formula_23, formula_35, formula_36, formula_37, formula_38, formula_39, formula_40, formula_41. Next, we perform linear interpolation between formula_23 and formula_35 to find formula_44, formula_38 and formula_39 to find formula_47, formula_40 and formula_41 to find formula_50, formula_36 and formula_37  to find formula_53. Now we do interpolation between formula_44 and formula_53 to find formula_56, formula_47 and formula_50 to find formula_59. Finally, we calculate the value formula_60 via linear interpolation of formula_56 and formula_59 In practice, a trilinear interpolation is identical to two bilinear interpolation combined with a linear interpolation: Alternative algorithm. An alternative way to write the solution to the interpolation problem is where the coefficients are found by solving the linear system yielding the result