[R] How to add/draw a persp3d graph to a plot with an existing surface/graph

Michael yhou168 at gmail.com
Mon Mar 12 22:45:33 CET 2012


Dear R users,

I have been trying to draw the following 3d graphs: The solid region bounded
above by the paraboloid z = 9 - x2 - y2 and below by the unit circle in the
xy-plane.

I wanted to visualize the solid region bounded by those two graphs. I could
draw those two 3d graphs separately, but I could not get those two to work
in one single plot.

Here's my code for the paraboloid:
x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { 9-x^2-y^2 }
z <- outer(x, y, f)
persp3d(x, y, z, aspect=c(1, 1, 1), col = "lightblue",
       xlab = "X", ylab = "Y", zlab = "9-x^2-y^2")

And my code for the cylinder with the unit circle as the base:

z <- matrix(seq(0, 1, len=50), 50, 50)
theta <- t(z)
x <- cos(theta*2*pi)
y <- sin(theta*2*pi)
persp3d(x, y, z, col="red",add=T)

I wonder if the other R users have encountered similar problems. If someone
can help me out, I'll be very appreciative.

Thanks a lot.

Michael

--
View this message in context: http://r.789695.n4.nabble.com/How-to-add-draw-a-persp3d-graph-to-a-plot-with-an-existing-surface-graph-tp4467497p4467497.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list