Trilinear interpolation

From The Right Wiki
Jump to navigationJump to search
File:3D interpolation2.svg
Trilinear interpolation as two bilinear interpolations followed by a linear 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 (x,y,z) within the local axial rectangular prism linearly, using function data on the lattice points. Trilinear interpolation is frequently used in numerical analysis, data analysis, and computer graphics.

Related methods

Trilinear interpolation is the extension of linear interpolation, which operates in spaces with dimension 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. 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.

Formulation

File:Enclosing points.svg
Eight corner points on a cube surrounding the interpolation point C

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:

xd=xx0x1x0yd=yy0y1y0zd=zz0z1z0

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 one interpolates along x (imagine one is "pushing" the face of the cube defined by C0jk to the opposing face, defined by C1jk), giving:

c00=c000(1xd)+c100xdc01=c001(1xd)+c101xdc10=c010(1xd)+c110xdc11=c011(1xd)+c111xd

Where c000 means the function value of (x0,y0,z0). Then one interpolates these values (along y, "pushing" from Ci0k to Ci1k), giving:

c0=c00(1yd)+c10ydc1=c01(1yd)+c11yd

Finally one interpolates these values along z (walking through a line):

c=c0(1zd)+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.

Algorithm visualization

File:Trilinear interpolation visualisation.svg
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.

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(b(c000,c010,c100,c110),b(c001,c011,c101,c111))

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

[1x0y0z0x0y0x0z0y0z0x0y0z01x1y0z0x1y0x1z0y0z0x1y0z01x0y1z0x0y1x0z0y1z0x0y1z01x1y1z0x1y1x1z0y1z0x1y1z01x0y0z1x0y0x0z1y0z1x0y0z11x1y0z1x1y0x1z1y0z1x1y0z11x0y1z1x0y1x0z1y1z1x0y1z11x1y1z1x1y1x1z1y1z1x1y1z1][a0a1a2a3a4a5a6a7]=[c000c100c010c110c001c101c011c111],

yielding the result

a0=c000x1y1z1+c001x1y1z0+c010x1y0z1c011x1y0z0(x0x1)(y0y1)(z0z1)+c100x0y1z1c101x0y1z0c110x0y0z1+c111x0y0z0(x0x1)(y0y1)(z0z1),a1=c000y1z1c001y1z0c010y0z1+c011y0z0(x0x1)(y0y1)(z0z1)+c100y1z1+c101y1z0+c110y0z1c111y0z0(x0x1)(y0y1)(z0z1),a2=c000x1z1c001x1z0c010x1z1+c011x1z0(x0x1)(y0y1)(z0z1)+c100x0z1+c101x0z0+c110x0z1c111x0z0(x0x1)(y0y1)(z0z1),a3=c000x1y1c001x1y1c010x1y0+c011x1y0(x0x1)(y0y1)(z0z1)+c100x0y1+c101x0y1+c110x0y0c111x0y0(x0x1)(y0y1)(z0z1),a4=c000z1+c001z0+c010z1c011z0+c100z1c101z0c110z1+c111z0(x0x1)(y0y1)(z0z1),a5=c000y1+c001y1+c010y0c011y0+c100y1c101y1c110y0+c111y0(x0x1)(y0y1)(z0z1),a6=c000x1+c001x1+c010x1c011x1+c100x0c101x0c110x0+c111x0(x0x1)(y0y1)(z0z1),a7=c000c001c010+c011c100+c101+c110c111(x0x1)(y0y1)(z0z1).

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].