# Dsgrid 3D interpolation

## Simplest usage

If the default settings for the control parameters are what you want, then you can interpolate on a grid by invoking a single procedure. Example 1 presents a simple 3D interpolation with codes using each of the four programmatic interfaces.

## Algorithmic details, control paramters

Given a point where an interpolated value is desired, the distance from that point to each of the known input points is calculated. Weights for each of the input points are calculated that are inversely proportional to the calculated distances raised to a power. The sum of the weights is normalized to unity and the interpolated value is the sum of the products of the function values at the input points and the weights.

The control parameter exp can be used to specify the power of the distances used in calculating the weights -- by default this value is 3.0. Example 2 illustrates the effect of varying the exponent used for the distances in the weight calculations. When the exponent is 1., cone-like surfaces are formed around the input data values; for values of the exponent greater than 1., flat spots occur around the input data values (the larger the exponent, the larger the flat spot); for values of the exponent smaller than 1., cusps are formed around the input data points.

The control parameter dmx can be used to supply a radius around an interpolation point outside of which input data points will not be used to calculate weights. If no input data points lie within the specified radius for a given interpolation point, the interpolated value is set to a special missing value. This missing value can be set using the control parameter dmv -- the default value is -9999.

## Smoothness

Due to the fact that the algorithm produces cusps or flat spots around the input data points (depending on the exponent of the distances as explained above), the interpolated surfaces or isosurfaces are, in general, not particularly smooth. Example 3, which is an approximation of an analytic function defined at random data points, illustrates this. In particular, compare the Dsgrid plot with the plot of the same interpolation done using Natgrid.

## Efficiency

For details on the efficiency of the algorithm, see the efficiency module.

## Single point mode for 3D

Dsgrid can be used to interpolate at individual points. The Fortran procedures for this are DSPNT3S and DSPNT3D; and the equivalent C procedures are c_dspnt3s and c_dspnt3d.

You can set any control parameters you want before interpolating at individual points.

For the same number of input and output points, using the Dsgrid entries for interpolation at individual points invokes about a 30% overhead compared to using the Dsgrid entries to interpolate on a grid.

## Extrapolation

In general extrapolation is not very reliable and the results so obtained are to be viewed with some lack of confidence. In order for extrapolation to be at all reliable, the original data must be very consistent.

Outside of the convex hull, the interpolated values in Dsgrid tend quickly toward a constant value. This constant is the arithmetic average of the input functional values. Example 5 illustrates this. It presents the function f(x,y) = (x-1/4)**2 + (y-1/2)**2 defined on the unit square and extrapolated to a rectangular region beyond that square.