如何在 R 中导入和绘制三角形网格? [英] How can I import and plot a triangular mesh in R?
问题描述
我想在 R 中绘制我的模型输出
I would like to plot my model output in R
它是一个三角形网格,格式为
It is a triangular mesh in the format
x1 y1 z1 x2 y2 z2 x3 y3 z3 value
其中每一行代表一个三角形,我想用 value
作为比例来绘制这些三角形.
Where each row represents a triangle, and I would like to plot these triangles with value
as the scale.
mymesh <- structure(c(0.91, 0.45, 13.93, 14.26, 14.15, 14.36, 14.36, 14.61,
14.58, 14.87, 14.8, 15.13, 15.02, 15.39, 15.24, 15.65, 15.46,
15.9, 15.69, 16.16, 0, 0.79, 12.45, 12.64, 12.34, 12.46, 12.24,
12.38, 12.13, 12.3, 12.03, 12.22, 11.92, 12.13, 11.81, 12.04,
11.69, 11.94, 11.57, 11.84, 0, 0, 208.71, 208.69, 210.7, 210.68,
212.68, 212.66, 214.67, 214.65, 216.66, 216.63, 218.64, 218.61,
220.62, 220.59, 222.61, 222.57, 224.59, 224.56, 0.45, 1.5, 14.15,
14.15, 14.36, 14.36, 14.58, 14.58, 14.8, 14.8, 15.02, 15.02,
15.24, 15.24, 15.46, 15.46, 15.69, 15.69, 15.92, 15.92, 0.79,
0, 12.34, 12.34, 12.24, 12.24, 12.13, 12.13, 12.03, 12.03, 11.92,
11.92, 11.81, 11.81, 11.69, 11.69, 11.57, 11.57, 11.45, 11.45,
0, 131.83, 210.7, 210.7, 212.68, 212.68, 214.67, 214.67, 216.66,
216.66, 218.64, 218.64, 220.62, 220.62, 222.61, 222.61, 224.59,
224.59, 226.58, 226.58, 1.5, 0.75, 14.26, 14.36, 14.36, 14.61,
14.61, 14.87, 14.87, 15.13, 15.13, 15.39, 15.39, 15.65, 15.65,
15.9, 15.9, 16.16, 16.16, 16.42, 0, 1.3, 12.64, 12.46, 12.46,
12.38, 12.38, 12.3, 12.3, 12.22, 12.22, 12.13, 12.13, 12.04,
12.04, 11.94, 11.94, 11.84, 11.84, 11.74, 131.83, 131.83, 208.69,
210.68, 210.68, 212.66, 212.66, 214.65, 214.65, 216.63, 216.63,
218.61, 218.61, 220.59, 220.59, 222.57, 222.57, 224.56, 224.56,
226.54, 375.12, 399.8, 297.84, 497.63, 368.17, 1113.19, 979,
781.41, 1202.21, 1113.94, 1293.77, 1391.94, 1364.52, 1151.37,
1690.98, 913.63, 0, 0, 0, 0), .Dim = c(20L, 10L), .Dimnames = list(
NULL, c("x1", "y1", "z1", "x2", "y2", "z2", "x3", "y3", "z3",
"value")))
我查看了 rgl
、plot3D
和 misc3d
包.然而,这些似乎处理的是点而不是三角形(例如,rgl.points
、rgl.linestrips
和 rgl.triangles
函数都以 x,y,z
作为输入,而不是一个三角形).
I have looked at the rgl
, plot3D
, and misc3d
packages. However, these seem to be dealing with points rather than triangles (for example, the rgl.points
, rgl.linestrips
, and rgl.triangles
functions all take x,y,z
as inputs, rather than a triangle).
如何使用 R 绘制此数据集中的三角形并为其着色?
How can I use R to plot and color the triangles in this dataset?
推荐答案
我使用 rgl
中的 shade3d
和 tmesh3d
函数生成了一个绘图.它创建了两个单独的条.不同的三角形有不同的颜色.看下图.
I generated a plot using the shade3d
and tmesh3d
functions from rgl
.
It creates two separate bars. The different triangulars are coloured differently. Look at the plot below.
rgl.open()
i <- 1
vertices <- c(mymesh[i,1:3],1,mymesh[i,4:6],1,mymesh[i,7:9],1)
indices <- c( 1, 2, 3)
shade3d( tmesh3d(vertices,indices) , col=1)
bg3d(color = "white")
for(i in 2:20){
vertices <- c(mymesh[i,1:3],1,mymesh[i,4:6],1,mymesh[i,7:9],1)
indices <- c( 1, 2, 3)
shade3d( tmesh3d(vertices,indices) , col= i)
}
这篇关于如何在 R 中导入和绘制三角形网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!