polygon3d {R.basic}R Documentation

Adds (planar) polygon to a three dimensional plot

Description

Adds a (planar) polygon to a three dimensional plot previously created by plot3d() or persp().

Usage

  polygon3d(x=seq(0, 1, len=nrow(z)), y=seq(0, 1, len=ncol(z)), z,
                            persp.matrix=getOption("persp.matrix"), ...)

Arguments

x the coordinates of polygon in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.
y the y coordinates of polyogon in the plot, optional if x is an appropriate structure.
z the z coordinates of polyogon in the plot, optional if x is an appropriate structure.
persp.matrix an 4-by-4 transformation matrix describing how to project the (x,y,z) text to the drawing canvas as the one returned by persp()
... further arguments accepted by polygon().

Author(s)

Henrik Bengtsson, http://www.braju.com/R/

See Also

For creating a 3D plot see plot3d. For adding points to a 3D plot see points3d. For adding text labels to a 3D plot see text3d. For adding lines to a 3D plot see lines3d. See also persp. Package scatterplot3d by Uwe Ligges. For detail about the graphical parameter arguments, see par.

Examples

n <- 32 + 1
theta <- seq(0, 2*pi, length.out=n)
#theta <- theta[-(n+1)]

x1 <- sin(theta)
y1 <- cos(theta)
z1 <- rep(1, n)

x0 <- rep(0, n)
y0 <- rep(0, n)
z0 <- rep(0, n)

plot3d(x1,y1,z1, type="n", zlim=c(0,1.3), xlab="x", ylab="y", zlab="z", phi=30)

#x1 <- c(x1, x1[1])
#y1 <- c(y1, y1[1])
#z1 <- c(z1, z1[1])

n <- n - 1;
for (k in c(1:n,1:n)[22+1:n-1]) {
  xs <- c(x0[k], x1[k], x1[k+1])
  ys <- c(y0[k], y1[k], y1[k+1])
  zs <- c(z0[k], z1[k], z1[k+1])
  col <- hsv(h=(k-1)/n, s=1, v=1)
  polygon3d(xs,ys,zs, col=col)
}

text3d(x1,y1,z1+0.1, 1:n)

[Package Contents]