Michael
2012-Mar-12 21:45 UTC
[R] How to add/draw a persp3d graph to a plot with an existing surface/graph
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.
Duncan Murdoch
2012-Mar-13 10:04 UTC
[R] How to add/draw a persp3d graph to a plot with an existing surface/graph
On 12-03-12 5:45 PM, Michael wrote:> 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. >I think the graph is working, it's just that the cylinder is really tiny and hard to see. Your z range goes from -190 to 9 in the first graph, but from 0 to 1 in the cylinder. Try using -200*z + 9 in the second plot, and you'll see the cylinder clearly. Duncan Murdoch