如何计算表面由三角形组成的 3D 网格对象的体积 [英] How to calculate the volume of a 3D mesh object the surface of which is made up triangles
问题描述
我想计算一个表面由三角形组成的 3D 网格对象的体积.
I want to calculate the volume of a 3D mesh object having a surface made up triangles.
推荐答案
阅读本文论文,其实是一个很简单的计算.
Reading this paper, it is actually a pretty simple calculation.
诀窍是计算四面体的有符号体积 - 基于您的三角形并在原点处结束.体积的符号来自于你的三角形是否指向原点的方向.(三角形的法线本身取决于顶点的顺序,这就是为什么您没有在下面看到它明确引用的原因.)
The trick is to calculate the signed volume of a tetrahedron - based on your triangle and topped off at the origin. The sign of the volume comes from whether your triangle is pointing in the direction of the origin. (The normal of the triangle is itself dependent upon the order of your vertices, which is why you don't see it explicitly referenced below.)
这一切都归结为以下简单的函数:
This all boils down to the following simple function:
public float SignedVolumeOfTriangle(Vector p1, Vector p2, Vector p3) {
var v321 = p3.X*p2.Y*p1.Z;
var v231 = p2.X*p3.Y*p1.Z;
var v312 = p3.X*p1.Y*p2.Z;
var v132 = p1.X*p3.Y*p2.Z;
var v213 = p2.X*p1.Y*p3.Z;
var v123 = p1.X*p2.Y*p3.Z;
return (1.0f/6.0f)*(-v321 + v231 + v312 - v132 - v213 + v123);
}
然后是计算网格体积的驱动程序:
and then a driver to calculate the volume of the mesh:
public float VolumeOfMesh(Mesh mesh) {
var vols = from t in mesh.Triangles
select SignedVolumeOfTriangle(t.P1, t.P2, t.P3);
return Math.Abs(vols.Sum());
}
这篇关于如何计算表面由三角形组成的 3D 网格对象的体积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!