How About a Boxcar?

A Boxcar Filter is a gadget that runs (or maps) a function of four arguments over a rectangular grid of points. A rectangular grid is a data structure where each point has a pair of integer indices, i and j, say, and i runs from, say, 1, through M and j runs from 1 through N. The data structure is best viewed as a function from i and j to some value, which can be anything. Even better, let it be a list of lists, in the usual Mathematica way. The function of four arguments that the Boxcar filter maps over the grid expects four, nearest-neighbor points:
   h[p1, p2, p3, p4],
      p1=grid[i, j], p2=[i+1, j], p3[i, j+1], p4[i+1, j+1]
The Boxcar filter mapper, then, must intelligently skip the last row and column. Enjoy:





      fRows[gCols[op4[#1, #2, #3, #4]&, #1, #2]&, grid];

Here’s an application that draws criss-crosses in each box of a grid. Ampersand converts the previous expression into a function (a lambda expression), in which #1, #2, … denote positional arguments. Thus, {Line[{#1,#4}],Line[{#2,#3}]}& is a function of four arguments:



~ by rebcabin on June 23, 2008.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: