## 7.1 Generating 3D data

By default, the objects that physica manipulates are vectors, i.e. inherently one-dimensional things. However, one can create a one-dimensional equivalent of a two-dimensional object by ``unraveling'' the m x n matrix like this:

The last line can then be thought of as a mapping , where

This presupposes that we know on a regular array of data points . Here's one quick way of creating such a mapping:

PHYSICA: generate j 0,,99 100
PHYSICA: x=int(j/10)*10
PHYSICA: y=j-x
PHYSICA: z=(x-50)**2*exp(-0.1*(y-5)**2)
PHYSICA: list x,y,z
PHYSICA: density\boxes x,y,z

We generated three vectors of length 100, and then interpreted them as a three-dimensional object. The \boxes switch shows off one more way of rendering such a ``surface''.

To do the surface justice, however, it is best to perform the reverse: take a set of vector (1D) data and then create a regularly-spaced grid matrix out of it:

PHYSICA: grid x y z m
PHYSICA: surface m 25 -30

Note that we have used our regular arrays x, y, and z to generate a matrix m, but in general grid command will interpolate data as needed, so the input data representing a surface need not be known at a regularly-spaced grid of points . For our arrays we could have used the option grid\nointerpolate since the data is already regularly spaced.

Up: 7. Surfaces, contours, and other 3D plots Next: 8. Real programming: if's and do's Previous: 7. Surfaces, contours, and other 3D plots