Skip to content

plotting intersecting planes

1 message · David Brahm

#
Peter Dunn wrote:
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