[R] plotting intersecting planes

David Brahm brahm at alum.mit.edu
Wed Nov 20 15:32:00 CET 2002


Peter Dunn wrote:
> But what about, say, plottting intersecting planes?  I can't seem to find a 
> way of plotting in 3D, and then adding another plot.

Here's a simple example.  As Paul Murrell said, though, there's no hidden
surface removal.

trans3d <- function(x,y,z, pmat) {                       # Thanks, Ben Bolker!
  tmat <- t(cbind(x,y,z,1) %*% pmat)
  list(x=tmat[1,]/tmat[4,], y=tmat[2,]/tmat[4,])
}

pmat <- persp(0:1,0:1,matrix(NA,2,2), xlim=c(-5,5), ylim=c(-5,5), zlim=c(0,2),
              theta=25, phi=30, expand=.5, xlab="X", ylab="Y", zlab="Z")
polygon(trans3d(c(-3,3,3,-3), c(-5,-5,5,5), c(2,0,0,2), pmat), border="blue")
polygon(trans3d(c(3,-3,-3,3), c(-5,-5,5,5), c(2,0,0,2), pmat), border="red")
lines(trans3d(c(0,0), c(-5,5), c(1,1), pmat))       # The line of intersection

-- 
                              -- David Brahm (brahm at alum.mit.edu)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list