简体   繁体   English

在R中使用rgl包测量不规则物体的体积

[英]Using rgl package in R to measure the volume of an irregular object

I have vertices (x,y,z coordinates) of an irregular object (all normals point outward) and I would like to calculate its volume.我有一个不规则物体的顶点(x、y、z 坐标)(所有法线都指向外),我想计算它的体积。 With small objects with just a handful of vertices, I can find the volume by calculating the volume of tetrahedrons for each triangle on the surface with respect to a reference point.对于只有少数顶点的小物体,我可以通过计算表面上每个三角形相对于参考点的四面体体积来找到体积。 I have a script that will do that for small number of faces and identifying the faces and order of the points is not too difficult.我有一个脚本可以为少量的人脸执行此操作,并且识别人脸和点的顺序并不太困难。 However, for a large number of points, identifying each group of 3 points is challenging and time consuming.然而,对于大量的点,识别每组 3 个点是具有挑战性和耗时的。 I think my first problem is that I need to convert my vertices into a mesh but I don't know how to do that.我认为我的第一个问题是我需要将顶点转换为网格,但我不知道该怎么做。 I have tried several commands in the rgl package but I'm not getting anywhere and I'm not understanding this step.我在 rgl 包中尝试了几个命令,但我没有得到任何地方,我不理解这一步。

Below is a sample of my data.下面是我的数据示例。 For each set of points, I slice my object and identify 6 vertices.对于每组点,我将对象切片并确定 6 个顶点。 plot3d(x,y,z) works nicely. plot3d(x,y,z) 效果很好。

index   x   y   z   point
1   -225.64 0.3 427.91  1
2   -225.64 0.3 233.32  2
3   -39.83  0.3 44.62   3
4   45.7    0.3 41.67   4
5   228.56  0.3 236.26  5
6   228.56  0.3 427.91  6
7   -227.47 75  427.52  1
8   -224.52 75  244.72  2
9   -77.05  75  82.56   3
10  73.36   75  82.56   4
11  229.68  75  232.92  5
12  229.68  75  427.52  6
13  -226.37 85  425.78  1
14  -224.75 85  236.55  2
15  -84.08  85  92.6    3
16  84.08   85  92.06   4
17  227.98  85  238.16  5
18  226.37  85  427.4   6
19  -226.37 95  426.39  1
20  -226.37 95  235.54  2
21  -95.4   95  102.91  3
22  93.78   95  102.91  4
23  226.37  95  235.54  5
24  236.37  95  426.39  6
25  -229.6  105 428.21  1
26  -224.75 105 240.59  2
27  -105.1  105 112.81  3
28  106.72  105 112.81  4
29  226.37  105 237.35  5
30  226.37  105 426.59  6
31  -226.37 115 426.59  1
32  -226.37 115 237.35  2
33  -114.8  115 122.52  3
34  114.8   115 124.14  4
35  227.98  115 237.35  5
36  226.37  115 426.59  6
37  -224.75 125 426.59  1
38  -226.37 125 235.74  2
39  -124.5  125 133.84  3
40  122.89  125 135.46  4
41  226.37  125 235.74  5
42  226.37  125 426.59  6
43  -226.37 135 428.21  1
44  -226.37 135 237.35  2
45  -134.2  135 143.54  3
46  135.82  135 143.54  4
47  226.37  135 237.35  5
48  226.37  135 426.59  6
49  -226.37 145 428.21  1
50  -226.37 145 237.35  2
51  -145.54 145 153.25  3
52  142.29  145 154.87  4
53  226.37  145 237.35  5
54  226.37  145 426.59  6
55  -226.37 155 428.21  1
56  -226.37 155 237.35  2
57  -174.63 155 185.4   3
58  174.63  155 185.4   4
59  226.37  155 237.35  5
60  226.37  155 426.59  6

I don't think rgl has a function that you need, but if the object is convex, geometry::convhulln can do what you want.我不认为rgl有你需要的函数,但如果对象是凸的, geometry::convhulln可以做你想做的。 Let's assume that obj contains the data you showed, then this calculates the volume of the convex hull:让我们假设obj包含您显示的数据,然后计算凸包的体积:

xyz <- obj[c("x", "y", "z")]
library(geometry)
hull <- convhulln(xyz, options = "FA")
hull$vol

This gives 20389437. The volume of the rectangular prism containing all of your points is 27863952, so that looks about right.这给出了 20389437。包含所有点的矩形棱柱的体积是 27863952,所以看起来差不多。

If your object is not convex, then maybe the alphashape3d package has something that would help you.如果您的对象不是凸面,那么alphashape3d包可能会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM