# INVDISTANCE

## Purpose:

Interpolates XYZ data to arbitrary XY coordinates using the inverse distance method.

## Syntax:

 xy - A 2 column series, the X (horizontal) and Y (vertical) input values. z - A single column series, the Z input height at coordinates X,Y. ri - A 2 column series, the desired output XY coordinates. weights - Optional. A series, the weights of distance function. Defaults to {0, 0, 1, 1, 1}. radius - Optional. A real, the maximum radius to include in the interpolation. Defaults to -1, all.

## Returns:

A series, the interpolated Z heights for the specified output coordinates.

## Example:

xi = grand(100, 1)*2 - 1;

yi = grand(100, 1)*2 - 1;

zi = cos(xi*yi);

(x, y) = fxyvals(-1, 1, 0.1, -1, 1, 0.1);

xo = x[..];

yo = y[..];

z1 = invdistance(ravel(xi,yi),zi,ravel(xo,yo));

z2 = invdistance(ravel(xi,yi),zi,ravel(xo,yo),{0, 1});

W1: xyz(xi, yi, zi);points;setsym(14)

W2: xyz(xo[..], yo[..], z1);points;setsym(14)

W3: xyz(xo[..], yo[..], z2);points;setsym(14)

This example demonstrates the interpolation of random samples of the function cos(x*y) over the XY range of –1 to 1. xi, yi and zi contain the original XYZ samples. xo and yo specify the desired output interpolation locations. z1 contains the interpolated Z values using the default weighting scheme and z2 contains the interpolated result using the classical inverse distance weighting function. W1, W2 and W3 display the results as XYZ plots.

## Remarks:

INVDISTANCE grids XYZ data over any arbitrary XY coordinates. However, a uniform grid is most useful for interpolating XYZ points to a surface. See IGRID to directly convert XYZ data to a surface by interpolating to a uniform grid.

The inverse distance method of gridding irregularly spaced XYZ data computes the new Z value at the specified output coordinates by computing the ratio of the known Z values to their distances from the desired output coordinate. If Z is the value to interpolate at point (x, y), then:

where Zi are the known values at (xi , yi). The weighting function is defined as:

p is an arbitrary value and the distance R is:

where (x, y) is the coordinate of the interpolation point and (xi , yi) are the coordinates of the known points. Thus R is the radius or distances from the interpolated value to the known input Z locations.

The new Z value is computed as a weighted sum of the distances from the desired location to the known locations. The weighting function varies from a value of 1.0 if the desired output point is located exactly at an input coordinate to a value approaching 0.0 as the distance from the desired output coordinate increases. Thus, the Z output values are most strongly influenced by samples located closest to the value being interpolated.

The classical technique, known as Shepard’s method, uses a single distance term with a typical value of p = 2, thus directly computing the inverse squared distance as the weighting function. By default, INVDISTANCE uses a linear combination of r-3 + r-4 + r-5 terms for better results. The optional WEIGHTS series specifies the weighting of the radius (distance) terms:

{r^-1, r^-2, r^-3, r^-4, ...}.

The default of {0, 0, 1, 1, 1} specifies a linear combination of r-3 + r-4 + r-5 terms. The series {0, 1} specifies the classical direct inverse squared distance weighting function.

INTERP2

SPLINE2