(注意:我用的是rgl version 0.96.0,如果我没记错的话wire3d()和dot3d()的规则已经改了)
在创建类mesh3d 对象时提供颜色信息不是一个好主意,因为shade3d()、wire3d() 和dot3d() 以不同的方式使用它。绘制对象时最好给绘图函数一个颜色信息。
例如;
A <- matrix(c( 1, 0, 1, 0, 2, 0, 1, 0, 2), 3, 3)
c3d2 <- cube3d()
c3d_trans2 <- cube3d(A)
colv <- rep(2:7, each=4)
shade3d(c3d2, col = colv, alpha = 0.8)
wire3d(c3d2); dot3d(c3d2, size = 5)
shade3d(c3d_trans2, col = colv, alpha=0.5)
dot3d(c3d_trans2, size = 5)
[与颜色和mesh3d.obj相关的细节]最重要的规则是顶点在使用时消耗颜色(但它是有点复杂,请看下面的例子)。我在下面调用矩阵 ib 和 mesh3d.obj$vb 的列号 index 。
cube3d()$ib
# [,1] [,2] [,3] [,4] [,5] [,6]
# [1,] 1 3 2 1 1 5
# [2,] 3 7 4 5 2 6
# [3,] 4 8 8 7 6 8
# [4,] 2 4 6 3 5 7
shade3d() 规则(很简单)
plot3d(cube3d(scaleMatrix(1.2,1.2,1.2)), alpha=0)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8) # indices
shade3d(cube3d(), col=c(rep(2,4), rep(3,4), rep(4,4), rep(5,4), rep(6,4), rep(7,4)), alpha=0.8)
# ib[1:4, 1] [1:4, 2] [1:4, 3] [1:4, 4] [1:4, 5] [1:4, 6]
# index 1,3,4,2 3,7,8,4 2,4,8,6, ...
wire3d 规则(复杂而可怕..;已编辑)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8, font=2) # indices
wire3d(cube3d(), col=c(rep(2,6), rep(3,6), rep(4,6), rep(5,6), rep(6,6), rep(7,6)))
# I gave each color 6 times.
index 1 3 4 2 1
ib$[1,1] - [2,1] - [3,1] - [4,1] - [1,1] - NA
col 2 2 2 2 2 2 # Why NA uses a color!!??
index 3 7 8 4 (skipped) 3 # the line already has been drawn, skipped.
ib$[1,2] - [2,2] - [3,2] - [4,2] - [1,2] - NA;
col 3 3 3 3 (skipped) 3 3
index 2 (sk) 4 (sk) 8 6 2
ib$[1,3] - [2,3] - [3,3] - [4,3] - [1,3] - NA;
col 4 (sk) 4 (sk) 4 4 4 4, and so on.
在一个ib 的col 中,一个顶点只有一种颜色(例如,在ib[,1],Index3 的颜色信息同时用于 1-3 和 3-4。当线条已经被绘制时,略过。用wire3d()画不同颜色的线太难了(有些图案是不可能的)。如果你想做,最好用lines3d()或@987654346 @
dot3d 规则
plot3d(cube3d(scaleMatrix(1.2,1.2,1.2)), alpha=0)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8) # indices
dot3d(cube3d(), col=1:8, size=8)
unique(c(cube3d()$ib))
# [1] 1 3 4 2 7 8 6 5
如果你给col=1:8,不是index2,但index3变成col = 2(red)。
所以,col = c("col1", "col2", ..., "col8")[unique(c(object$ib))]意味着index1是col1,index2是col2。