R:在3d中绘制三角形的边缘

时间:2017-03-20 15:02:44

标签: r plot 3d rgl

我有一个生活在三维空间中的三角形,我想以有效的方式仅绘制三角形的边缘,因为我将重复它以获得大量的三角形。

我可以使用包rgl:

将其绘制为彩色表面
rgl.open()
vertices = c(
0,0,0,1,
1,1,0,1,
0,0,1,1)
col = "blue"
shade3d( tmesh3d(vertices,indices) , col=col)
bg3d(color = "white")

但我想要的只是连接点的3条线。

我尝试的是:

vertices = c(
  0,0,0,
  1,1,0,
  0,0,1) 
rgl.lines(x=c(vertices[1],vertices[4]),y=c(vertices[2],vertices[5]),z=c(vertices[3],vertices[6]),col="black")
        rgl.lines(x=c(vertices[4],vertices[7]),y=c(vertices[5],vertices[8]),z=c(vertices[6],vertices[9]),col="black")
        rgl.lines(x=c(vertices[7],vertices[1]),y=c(vertices[8],vertices[2]),z=c(vertices[9],vertices[3]),col="black")
        bg3d(color = "white")

然而,这种方法比第一种方法慢得多(在真实网格上尝试时大约10次)。 我想知道,有没有办法用shade3d绘制三角形,只用它们的边缘透明?

2 个答案:

答案 0 :(得分:2)

你应该能够做到这样的事情:

wire3d( tmesh3d(vertices,indices) , col=col)

适合我。

使用我在rgl docs中找到的东西的示例:

library(rgl)

# A trefoil knot
open3d()
theta <- seq(0, 2*pi, len = 25)
cen <- cbind( sin(theta) + 2*sin(2*theta),
              2*sin(3*theta),
              cos(theta) - 2*cos(2*theta) )

e1 <- cbind( cos(theta) + 4*cos(2*theta),
             6*cos(3*theta), 
             sin(theta) + 4*sin(2*theta) )

knot <- cylinder3d( center=cen,e1=e1,radius = 0.8, closed = TRUE)

wire3d(addNormals(subdivision3d(knot, depth = 2)), col = "green")  

的产率:

enter image description here

使用时:

shade3d(addNormals(subdivision3d(knot, depth = 2)), col = "green")  

的产率:

enter image description here

答案 1 :(得分:0)

几周前我尝试过这样的事情(Stackoverflow question):

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

我希望这能为解决问题提供指导