2017-01-01 157 views
0

如何繪製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) 

任何提示我感謝!

我編輯了要點!

回答

4

你可以使用plot3drgl做到這一點:

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

+0

我編輯的點。你的答案是完美的。你能編輯你的數字嗎?然後,答案將完成。 –

+0

謝謝。我編輯了這個圖,並添加了一些評論,以便爲具有相同問題的其他用戶清楚。 – LyzandeR

+0

可以顯示修改'type =「l」'的參數'type =「p」'的立方體。 –