Reputation: 430
How to plot n
overlaid cubes? For example,
#cube 1
x1 <- c(0,1,1,0,0, 1,1,1,1,1, 1,1,0,0,1, 0,0,0,0,0, 0,1,1,0,0, 0,1,1,0,0)
y1 <- c(1,1,1,1,1, 1,0,0,1,1, 0,0,0,0,0, 0,0,1,1,0, 1,1,0,0,1, 1,1,0,0,1)
z1 <- c(0,0,1,1,0, 0,0,1,1,0, 0,1,1,0,0, 0,1,1,0,0, 0,0,0,0,0, 1,1,1,1,1)
#cube 2
x2 <- .5*c(0,1,1,0,0, 1,1,1,1,1, 1,1,0,0,1, 0,0,0,0,0, 0,1,1,0,0, 0,1,1,0,0)
y2 <- .5*c(1,1,1,1,1, 1,0,0,1,1, 0,0,0,0,0, 0,0,1,1,0, 1,1,0,0,1, 1,1,0,0,1)
z2 <- .5*c(0,0,1,1,0, 0,0,1,1,0, 0,1,1,0,0, 0,1,1,0,0, 0,0,0,0,0, 1,1,1,1,1)
#cube 3
x3 <- .3*c(0,1,1,0,0, 1,1,1,1,1, 1,1,0,0,1, 0,0,0,0,0, 0,1,1,0,0, 0,1,1,0,0)
y3 <- .3*c(1,1,1,1,1, 1,0,0,1,1, 0,0,0,0,0, 0,0,1,1,0, 1,1,0,0,1, 1,1,0,0,1)
z3 <- .3*c(0,0,1,1,0, 0,0,1,1,0, 0,1,1,0,0, 0,1,1,0,0, 0,0,0,0,0, 1,1,1,1,1)
Any tip I thank!
Upvotes: 0
Views: 132
Reputation: 37889
You could use plot3d
from rgl
to do this:
library(rgl)
#first cube
plot3d(x1, y1, z1, type="p", col="red", xlab="x",
ylab="y", zlab="z", site=5, lwd=15)
#second cube (notice add=TRUE to overlay)
plot3d(x2, y2, z2, type="p", col="blue", xlab="x",
ylab="y", zlab="z", site=5, lwd=15, add=TRUE)
#third cube (notice add=TRUE to overlay)
plot3d(x3, y3, z3, type="p", col="green", xlab="x",
ylab="y", zlab="z", site=5, lwd=15, add=TRUE)
Output:
Upvotes: 4