在3D绘图中填充两个线段之间的区域{rgl}

时间:2017-03-16 17:44:05

标签: r 3d polygon rgl

我使用包{rgl}中的函数plot3d()使用顶点坐标和线段制作了四面体。以下代码生成mentioned plot

library("rgl")
CCl4=c(5,5,5,10)
Luminol=c(0.01,0.001,0.005,0.005)
Na2CO3=c(0.01,0.01,0.1,0.05)

plot3d( Luminol, Na2CO3, CCl4, type = "s")

for(i in 1:4){
    for(k in 1:4){
                 segments3d(x=Luminol[c(i,k)],y=Na2CO3[c(i,k)],z=CCl4[c(i,k)])
                 }
        }

现在,我想填充点之间的区域(最好使用RGB颜色,这样我就可以使用alpha值定义透明度)但是我还没有在rgl中找到像polygon一样的函数。有没有办法填补这个区域?

提前致谢。

1 个答案:

答案 0 :(得分:3)

这是你在找什么?在请求上没有完全清楚。我为所有东西添加了颜色以帮助弄清楚它。

library("rgl")
CCl4=c(5,5,5,10)
Luminol=c(0.01,0.001,0.005,0.005)
Na2CO3=c(0.01,0.01,0.1,0.05)

clrs <- c("red","blue","green","darkgrey")

plot3d( Luminol, Na2CO3, CCl4, type = "s",col=clrs)

for(i in 1:4){
  clr <- clrs[i]
  for(k in (i+1):4){
      v <- c(i,k)
      segments3d(Luminol[v],Na2CO3[v],CCl4[v],color=clr)
  }
}

for (i in 1:4){
  clr <- clrs[i]
  v <- setdiff(1:4,i)
  triangles3d(Luminol[v],Na2CO3[v],CCl4[v],alpha=0.5,col=clr)
}

得到以下特性:

enter image description here