What is the DIST Function Used For?

QUESTION: What is the purpose of the DIST function in IDL? I see it used all the time, but I don't have any idea what it does or why it is there.

ANSWER: The DIST function implements an Euclidean distance function. This is a 2D array in which each element represents the Euclidean distance to the nearest corner of the image. The following IDL code, supplied by Paolo Grigis, could be used to create a DIST function:

   n = 12
   m = 15

   array = FltArr(n,m)

   FOR i=0L,n-1 DO BEGIN
       FOR j=0L,m-1 DO BEGIN
          i2 = MIN([i,n-i])
          j2 = MIN([j,m-j])
          array [i,j] = SQRT(i2^2 + j2^2)
       ENDFOR
   ENDFOR

   !P.MULTI = [0,2,1]
   Window, XSIZE=700, YSize=350, /Free
   Surface, array
   Surface, DIST(12,15)
   !P.MULTI = 0

The results of running the code are shown in the figure below.

Building a DIST function.
The constructed DIST function on the left and the IDL DIST function on the right.
 

Although, in practice, the DIST function is most often used to simulate some kind of 2D array for plotting purposes, it exists primarily because it is needed to construct many types of digital image filters. For example, a Butterworth low-pass frequency filter is constructed with commands similar to this:

   filter = 1.0 / ( 1.0d + (DIST(248)/15.0)^2 )

Google
 
Web Coyote's Guide to IDL Programming