Learn R Programming

rgl (version 0.111.6)

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)
terrain3d(x, y, z, ..., normal_x = NULL, normal_y = NULL, normal_z = NULL)

Arguments

x, y, z

vectors or matrices of values. See Details.

...

Material and texture properties. See rgl.material for details.

normal_x, normal_y, normal_z

matrices giving the coordinates of normals at each grid point

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.

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.

surface3d always draws 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.

surface3d and terrain3d are synonyms.

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