# persp3d: Surface plots In rgl: 3D Visualization Using OpenGL

## Description

This function draws plots of surfaces in 3-space. persp3d is a generic function.

## Usage

 1 2 3 4 5 6 7 persp3d(x, ...) ## Default S3 method: persp3d(x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z, xlim = NULL, ylim = NULL, zlim = NULL, xlab = NULL, ylab = NULL, zlab = NULL, add = FALSE, aspect = !add, forceClipregion = FALSE, ...)

## Arguments

 x, y, z points to plot on surface. See Details below. xlim, ylim, zlim x-, y- and z-limits. If present, the plot is clipped to this region. xlab, ylab, zlab titles for the axes. N.B. These must be character strings; expressions are not accepted. Numbers will be coerced to character strings. add whether to add the points to an existing plot. aspect either a logical indicating whether to adjust the aspect ratio, or a new ratio. forceClipregion force a clipping region to be used, whether or not limits are given. ... additional material parameters to be passed to surface3d and decorate3d.

## Details

The default method plots a surface defined as a grid of (x,y,z) locations in space. The grid may be specified in several ways:

• As with persp, x and y may be given as vectors in ascending order, with z given as a matrix. There should be one x value for each row of z and one y value for each column. The surface drawn will have x constant across rows and y constant across columns. This is the most convenient format when z is a function of x and y which are measured on a regular grid.

• x and y may also be given as matrices, in which case they should have the same dimensions as z. The surface will combine corresponding points in each matrix into locations (x,y,z) and draw the surface through those. This allows general surfaces to be drawn, as in the example of a spherical Earth shown below.

• If x is a list, its components x\$x, x\$y and x\$z are used for x, y and z respectively, though an explicitly specified z value will have priority.

One difference from persp is that colors are specified on each vertex, rather than on each facet of the surface. To emulate the persp color handling, you need to do the following. First, convert the color vector to an (nx - 1) by (ny - 1) matrix; then add an extra row before row 1, and an extra column after the last column, to convert it to nx by ny. (These extra colors will not be used). For example, col <- rbind(1, cbind(matrix(col, nx - 1, ny - 1), 1)). Finally, call persp3d with material property smooth = FALSE.

See the “Clipping” section in plot3d for more details on xlim, ylim, zlim and forceClipregion.

## Value

This function is called for the side effect of drawing the plot. A vector of shape IDs is returned invisibly.

Duncan Murdoch