r - draw cube into 3D scatterplot in RGL -


i'm trying add smaller cube/mesh (with specified side length) 3d scatterplot. i'd cube positioned @ origin. how go doing that? i've played around cube3d() can't seem position cube right nor make mesh (so can see data points contains. here's have:

library(rgl) x <- runif(100) y <- runif(100) z <- runif(100) plot3d(x,y,z, type="p", col="red", xlab="x", ylab="y", zlab="z", site=5, lwd=15) 

there cube3d function default returns list object (but not plot it) represents cube spanning x:[-1,1]; y:[-1,1]; z:[-1,1]. if apply color sides, solid default. need make sides transparent 'alpha" (see ?rgl.materials). if start out plot used:

library(rgl) x <- runif(100) y <- runif(100) z <- runif(100) plot3d(x,y,z, type="p", col="red", xlab="x", ylab="y", zlab="z", site=5, lwd=15) c3d <- cube3d(color="red", alpha=0.1)  # nothing happens yet c3d   # @ structure shade3d(c3d)   # render object 

this expands plot default dimensions of transparent red cube mentioned above. vertices @ xyz location in first 3 rows of $vb element:

c3b$vb      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]   -1    1   -1    1   -1    1   -1    1 [2,]   -1   -1    1    1   -1   -1    1    1 [3,]   -1   -1   -1   -1    1    1    1    1 [4,]    1    1    1    1    1    1    1    1 

now make cube has 1 of vertices @ origin, quickest way think of set -1's 0:

 c3d.origin <- cube3d(color="red", alpha=0.1)  c3d.origin$vb [c3d.origin$vb == -1] <- 0  shade3d(c3d.origin)  rgl.snapshot("cubes3d.png") 

enter image description here


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -