BILINEAR Function

Standard Library function that creates an array containing values calculated using a bilinear interpolation to solve for requested points interior to an input grid specified by the input array.

Usage

    result = BILINEAR(array, x, y)

Input Parameters

array—The array that is interpolated. The array must be a two-dimensional floating-point array with dimensions (n, m).

x—A floating-point array containing the x subscripts of array (see Discussion). Must satisfy the following conditions:

    0 ≤ min(x) < n

    0 < max(x) ≤ n

y—A floating-point array containing the y subscripts of array (see Discussion). Must satisfy the following conditions:

    0min(y) < m

    0 < max(y) ≤ m

Returned Value

result—A two-dimensional floating-point array (n, m) containing the results of the bilinear interpolation for the requested points.

If x is of dimension i and y is of dimension j, the result has dimensions (i, j). In other words, both x and y will be converted to (i, j) dimensions. If you want the result to have dimensions (i, j), then x can be either FLTARR(i) or FLTARR(i, j). This is also true for y.

Keywords

None.

Discussion

Given a two-dimensional input array, BILINEAR uses the specified set of reference points to compute each element of an output array with a bilinear interpolation algorithm.

The array x/y contains the X/Y subscripts of the elements in array that are used for the interpolation:

  • If x is a one-dimensional array, the same subscripts are used in each row of the output array.

  • If x is a two-dimensional array, different X subscripts may be used on each row of the output array.

  • If y is a one-dimensional array, the same subscripts are used in each column of the output array.

  • If y is a two-dimensional array, different Y subscripts may be used on each column of the output array.

Note that specifying x and y as two-dimensional arrays allows you to independently define the X and Y location of each point to be interpolated from the original array.

Note: Using two-dimensional arrays for x and y with BILINEAR in-creases the speed of the algorithm. If x and y are one-dimensional, they are converted to two-dimensional arrays before they are returned by the function. This permits them to be reused in subsequent calls to BILINEAR, thereby saving time.

Conversely, BILINEAR can be time consuming for large, one-dimensional arrays.

Example 1

; Create array that is all zeros except for a center value of 1.
array = FLTARR(3,3)
array(1, 1) = 1
; Find values where x = .1, .2 and y = .1, .4, .7, .9, knowing that
; when x = 1 and y = 1, the value in array is 1, but at all other
; points it is zero.
x = [.1, .2] 
PRINT, BILINEAR(a
y = [.1, .4, .7, .9]rray, x, y)
; PV-WAVE prints: 0.0100000    0.0200000
; PV-WAVE prints: 0.0400000    0.0800000
; PV-WAVE prints: 0.0700000    0.140000
; PV-WAVE prints: 0.0900000    0.180000

Example 2

; Create original data.
a = DIST(100)
original = SHIFT(SIN(a/5)/EXP(a/50),50,50)
; Load color table 5.
LOADCT, 5
; Display data.
TVSCL, original
; Make an array of linear values from 0 to 99.
b = FINDGEN(100)
; Look at b.
PLOT, b
; Create exponentially "warped" arrays to be used for spacing on
; the x-axis.
x = b^2 / 100.0
; Look at x; it is non-linear.
OPLOT, x
; Set y equal to x.
y = x
; Perform bilinear interpolation from "original" to "result"
; based on the (non-linear) spacing characteristics of the 
; indices in x and y.
result = BILINEAR(original, x, y)
ERASE
TVSCL, result

Note that original data has been interpolated in the upper right corner of "result" due to the non-linearity of the x- and y-axis arrays.

See Also

CONGRID,  INTERPOL,  SPLINE