Trilinear Interpolation
This section describes the trilinear interpolation algorithm using pseudo-Fortran code.
First, number the eight vertices of a hexahedron.
Defined as below, notice that xa = x1 when a = &S722;1 and that xa = x2 when a = 1 and similar observations for the rest of the equations.
Take three steps of substitutions.
Regrouping
Define
Then define
Exactly similar relations can be derived for y and z.
where the g's and h's are defined exactly similarly to the f's. Note that in the three equations above everything is known except for a, b and g. From the expression for x, and the similar equations for y and z, it is seen that
So the three equations can be solved for the unknowns a, b and g. A solution can be obtained from Newton's method by letting
where
Regrouping
Similarly
Using an initial guess of a = b = g = 0 the three equations can be solved for da, db and dg. Then one has
If the matrix of the coefficients are zero it is because the hexahedron is degenerate. The new a, b and g can be used to compute new coefficients and solve for new deltas and iteration should continue util the deltas are negligible. The interpolating program has a hard-wired limit of 20 iterations. If after 20 iterations or if the absolute values of any of the three parameters exceed 5.0, then the method fails and the starting stencil is returned as the "best" one.
After a, b and g have been computed the interplated value of any variable known at the vertices can be computed by
This equation was copied from the equation for X and can easily be verified by letting a, b and g take on their extreme values of ±1. If (x,y,z) is inside the hexahedron, then the parameters a, b and g will be between ±1. If one of them is outside those limits then the given point is outside the hexahedron and the above formula becomes an extrapolation, not an interpolation.