Learn R Programming

rgl (version 1.2.8)

surface3d: Add surface

Description

Adds a surface to the current scene. The surface is defined by a matrix defining the height of each grid point and two vectors or matrices defining the grid.

Usage

surface3d(x, y, z, ..., 
         normal_x = NULL, normal_y = NULL, normal_z = NULL,
         texture_s=NULL, texture_t=NULL, flip = FALSE)

Arguments

x, y, z

vectors or matrices of values. See Details.

...

Material properties. See material3d for details.

normal_x, normal_y, normal_z

matrices giving the coordinates of normals at each grid point

texture_s, texture_t

matrices giving the texture coordinates at each grid point

flip

flip definition of “up”

Details

Adds a surface mesh to the current scene. The surface is typically defined by a matrix of height values in z (as in persp), but any of x, y, or z may be matrices or vectors, as long as at least one is a matrix. (One historical exception is allowed: if all are vectors but the length of z is the product of the lengths of x and y, z is converted to a matrix.)

Dimensions of all matrices must match.

If any of the coordinates are vectors, they are interpreted as follows:

  • If x is a vector, it corresponds to rows of the matrix.

  • If y is a vector, it corresponds to columns of the matrix.

  • If z is a vector, it corresponds to columns unless y is also a vector, in which case it corresponds to rows.

If the normals are not supplied, they will be calculated automatically based on neighbouring points.

Texture coordinates run from 0 to 1 over each dimension of the texture bitmap. If texture coordinates are not supplied, they will be calculated to render the texture exactly once over the grid. Values greater than 1 can be used to repeat the texture over the surface.

surface3d always tries to draw the surface with the `front' upwards (typically towards higher z values). This can be used to render the top and bottom differently; see material3d and the example below. If you don't like its choice, set flip = TRUE to use the opposition definition.

NA values in the height matrix are not drawn.

See Also

See persp3d for a higher level interface.

Examples

Run this code
#
# volcano example taken from "persp"
#

z <- 2 * volcano        # Exaggerate the relief

x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)

zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1

colorlut <- terrain.colors(zlen) # height color lookup table

col <- colorlut[ z - zlim[1] + 1 ] # assign colors to heights for each point

open3d()
surface3d(x, y, z, color = col, back = "lines")

Run the code above in your browser using DataLab