# One Dimensional Grids

Today I implemented a custom grid that is useful for 1D structures such as the spiral above. Although an array or List would work decently, using a proper grid allows you to take advantage of the mapping technology and algorithms that is already built.

If you want to check out the code, here it is:

Import this into a project that contains *Grids*, and duplicate the **RectTest** scene, and replace the
RectTest script with
LineTest. (You may also want to change the cell to a circular one).

The package contains the classes
LineGrid,
LineMap,
LinePoint,
LineOp and
LineShapeInfo — all the basics of a proper grid. However, this grid does not support *quite* all the features of the built-in grids. To do that, we would have to change our text templates a bit (some code for built-in grids is generated from these templates); we would have to do the same to support 3D grids.

As is usual, the most difficult part to implement is the map. Although the spiral is given by simple parametric equations, what we really need is the natural parameterization so that cells are equally spaced. It turns out, for arbitrary curves, we cannot usually find a closed-form solution. I could not find one for the Archimedian spiral, and after almost spending the entire day trying, I just kind of guessed a function that seems to work (it was more a trial-and-error process than a direct guess!) Normally, numerical methods are used, and this is something we will look at if we make this part of our library.

Of course, working out a suitable equation for the spiral is just one half of the work – the inverse mapping is even trickier. Although the equation is easily invertible, the fact that we map regions and not points to grid points complicates the situation severely. In the end, I decided to just do a search through all the points; this is clearly not efficient. Making it easier to implement inverse map functions is another issue we want to look at.

The experiment also exposed some other minor flaws in our map tech – things that are not easy to see in many of the grids we have worked with so far. This has mostly to do with the helper functions, how cell dimensions should be interpreted, and the assumptions we made.

These are all tough problems; however, solving them will make all types of interesting grids easier to implement 🙂