Fill area between two segments in a 3D plot {rgl}

做~自己de王妃 提交于 2020-01-05 08:01:26

问题


I have made a tetrahedron using vertex coordinates and line segments using the function plot3d() from the package {rgl}. The code below makes the 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)])
                 }
        }

Now, I want to fill the area between the points (preferably using a RGB color so I can define transparency using an alpha value) but I have not found a polygon() like function in rgl. Is there a way to fill this area?

Thanks in advance.


回答1:


Is this what you are looking for? Wasn't completely clear on the request. I added color to everything to help figure it out.

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)
}

yielding:



来源:https://stackoverflow.com/questions/42841274/fill-area-between-two-segments-in-a-3d-plot-rgl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!