5.7.1 Two-dimensional interpolation

In the case of two-dimensional interpolation, the type of interpolation to be used is set using the interpolate modifier to the set samples command, and may be changed at any time after the interpolation function has been created. The options available are nearest neighbor interpolation – which is the two-dimensional equivalent of stepwise interpolation, inverse square interpolation – which returns a weighted average of the supplied data points, using the inverse squares of their distances from the requested point in argument space as weights, and Monaghan Lattanzio interpolation, which uses the weighting function (Monaghan & Lattanzio 1985)

  $\displaystyle  w(x)  $ $\displaystyle  = 1 - \nicefrac {3}{2}v^2 + \nicefrac {3}{4}v^3  $ $\displaystyle  \, \mathrm{for~ }0\leq v\leq 1  $    
  $\displaystyle  $ $\displaystyle  = \nicefrac {1}{4}(2-v)^3  $ $\displaystyle  \, \mathrm{for~ }1\leq v\leq 2  $    

where $v=r/h$ for $h=\sqrt {A/n}$, $A$ is the product $(x_\mathrm {max}-x_\mathrm {min})(y_\mathrm {max}-y_\mathrm {min})$ and $n$ is the number of input datapoints. These are selected as follows:

set samples interpolate nearestNeighbor
set samples interpolate inverseSquare
set samples interpolate monaghanLattanzio

The following example creates a function quad­ra­pole(x,y) which interpolates a quadrapole:

set samples interpolate inverseSquare
interpolate 2d quadrapole() '--'
-1 -1  1
-1  1 -1
 1 -1 -1
 1  1  1
END

Finally, data can be imported from graphical images in bitmap (.bmp) format to produce a function of two arguments returning a value in the range $0\to 1$ which represents the data in one of the image’s three color channels. The two arguments are the horizontal and vertical position within the bitmap image, as measured in pixels. This is done using syntax of the form:

interpolate 2d bmp_b blue() 'myImg.bmp'