polygon3d: Adds (planar) polygon to a three dimensional plot

Description Usage Arguments Author(s) See Also Examples

Description

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

Usage

1
2
## Default S3 method:
polygon3d(x, y=NULL, z=NULL, 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()

. Default value is getOption("persp.matrix"), which is set by plot3d().

...

further arguments accepted by polygon.

Author(s)

Henrik Bengtsson

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)

HenrikBengtsson/R.basic documentation built on May 6, 2019, 11:51 p.m.