next up previous contents index
Next: pl3tree: add a surface Up: The 3D Plotting Functions Previous: plwf: plot a wire   Contents   Index


pl3surf: plot a 3-D surface

Calling Sequence
...

  
pl3surf (nverts, xyzverts [, values] [, <keylist>])

Description
Perform simple 3D rendering of an object created by slice3 (possibly followed by slice2). nverts and xyzverts are polygon lists as returned by slice3, so xyzverts is sum (nverts)-by-3, where nverts is a list of the number of vertices in each polygon. If present, the values should have the same length as nverts; they are used to color the polygon. If values is not specified, the 3D lighting calculation set up using the light3 function will be carried out. Keywords cmin and cmax as for plf, pli, or plfp are also accepted. (If you do not supply values, you probably want to use the ambient keyword to light3 instead of cmin here, but cmax may still be useful.)

pl3surf calls clear3 before putting the plot command on the display list, which means that PyGist can only show one surface at a time using this function. (See pl3tree below for graphs with multiple components).

Example
The following example is the familiar sombrero function. The first few lines of code compute its value.

nc1 = 100 
nv1 = nc1 + 1 
br = -(nc1 / 2) 
tr = nc1 / 2 + 1 
x = arange (br, tr, typecode = Float) * 40. / nc1 
y = arange (br, tr, typecode = Float) * 40. / nc1 
z = zeros ( (nv1, nv1), Float) 
r = sqrt (add. outer ( x ** 2, y ** 2)) + 1e-6 
z = sin (r) / r

In order to use pl3surf, we need to construct a mesh using mesh3. The way we shall do that is to define a function on the 3d mesh so that the sombrero function is its 0-isosurface.

z0 = min (ravel (z)) 
z0 = z0 -.05 * abs (z0) 
maxz = max (ravel (z)) 
maxz = maxz + .05 * abs (maxz) 
zmult = max (max (abs (x)), max (abs (y))) 
dz = (maxz -z0) 
nxnynz = array ( [nc1, nc1, 1], Int) 
dxdydz = array ( [1.0, 1.0, zmult* dz], Float ) 
x0y0z0 = array ( [float (br), float (br), z0* zmult], Float ) 
meshf = zeros ( (nv1, nv1, 2), Float ) 
meshf [:, :, 0] = zmult* z -(x0y0z0 [2]) 
meshf [:, :, 1] = zmult* z -(x0y0z0 [2] + dxdydz [2])

Finally, we create the mesh and call the plotting functions.

m3 = mesh3 (nxnynz, dxdydz, x0y0z0, funcs = [meshf]) 
fma () 
# Make sure we don't draw till ready 
set_draw3_(0) 
pldefault( edges= 0) 
[nv, xyzv, col] = slice3 (m3, 1, None, None, value = 0.) 
orient3 () # (default orientation) 
pl3surf (nv, xyzv) 
lim = draw3 (1) 
dif = 0.5 * (lim [3] -lim [2]) 
# dif is used to compress the y scale a bit. 
limits (lim [0], lim [1], lim [2] -dif, lim [3] + dif) 
palette (" gray. gp")

The graph that results from this sequence of code is on the next page. This next sequence of functions uses slice3mesh to draw the same surface; this time the polygons that make up the surface are colored according to height (using the rainbow palette).

# Try new slicing function to get color graph 
[nv, xyzv, col] = slice3mesh (nxnynz [0: 2], dxdydz [0: 2], 
x0y0z0 [0: 2], zmult * z, color = zmult * z) 
pl3surf (nv, xyzv, values = col) 
lim = draw3 (1) 
dif = 0.5 * (lim [3] -lim [2]) 
limits (lim [0], lim [1], lim [2] -dif, lim [3] + dif) 
palette (" rainbow. gp")


next up previous contents index
Next: pl3tree: add a surface Up: The 3D Plotting Functions Previous: plwf: plot a wire   Contents   Index
Michiel Jan Laurens de Hoon 2003-04-19