我有一个位于 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将三角形绘制为仅具有边缘的透明三角形?
最佳答案
你应该能够做到这样的事情:
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")
产量:
关于R:在 3d 中绘制三角形的边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42907057/