【问题标题】:R: plot edges of a triangle in 3dR:在 3d 中绘制三角形的边缘
【发布时间】:2017-03-20 15:02:44
【问题描述】:

我有一个生活在 3d 空间中的三角形,我想以一种有效的方式只绘制三角形的边缘,因为我会为大量的三角形重复它。

我可以使用包 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 将三角形绘制成只有边缘的透明?

【问题讨论】:

  • 您的示例不起作用 - 没有声明或定义 indices。所以我使用了来自rgl 文档的示例。
  • 对我的回答有任何反馈吗?

标签: r plot 3d rgl


【解决方案1】:

你应该可以这样做:

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

为我工作。

使用我在 rgl 文档中找到的内容的示例:

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

产量:

在哪里使用:

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

产量:

【讨论】:

    【解决方案2】:

    几周前我尝试过这样的事情 (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)])
                     }
            }
    

    我希望这可以为解决您的问题提供指导

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 2015-11-30
      • 2020-12-15
      相关资源
      最近更新 更多