如何绘制重叠的立方体

时间:2017-01-01 17:21:02

标签: r 3d

如何绘制n重叠多维数据集?例如,

#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)

我感谢任何提示!

我编辑了分数!

1 个答案:

答案 0 :(得分:4)

您可以使用plot3d中的rgl来执行此操作:

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)

输出:

enter image description here