To demonstrate the effect of linear transformations in 3D,
x -> A x, I want to draw a cube and show its transformation under
A. For this, I need to color each face separately, and also show the vertex points and the lines that outline each face.
I can't figure out how to use distinct colors for the faces, and how to make this more general so I don't have to repeat all the steps for the result under the transformation.
what I tried:
library(rgl) c3d <- cube3d(color=rainbow(6), alpha=0.5) open3d() shade3d(c3d) points3d(t(c3d$vb), size=5) for (i in 1:6) lines3d(t(c3d$vb)[c3d$ib[,i],])
This gives the image below. But I don't understand how the faces are colored. And, I seem to have to use
lines3d on the components of the
c3d shape, and don't have a single object I can transform.
A particular transformation is given by the matrix
A below, and here is how I add that to the scene,
A <- matrix(c( 1, 0, 1, 0, 2, 0, 1, 0, 2), 3, 3) c3d_trans <- transform3d(c3d, A) shade3d( c3d_trans ) points3d(t(c3d_trans$vb), size=5)
Is there some way to simplify this and make it more generally useful?