如何计算三维网格物体的体积,三维网格物体的表面由三角形组成 [英] How to calculate the volume of a 3D mesh object the surface of which is made up triangles

查看:601
本文介绍了如何计算三维网格物体的体积,三维网格物体的表面由三角形组成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算一个三维网格物体的体积,它的表面由三角形组成。 http://chenlab.ece.cornell.edu/Publication/Cha/icip01_Cha.pdf =noreferrer>阅读本文,这实际上是一个相当简单的计算。



诀窍是计算四面体的有符号体积 - 根据您的三角形并在原点处标出。音量的标志来自您的三角形是否指向原点的方向。 (三角形的法线本身取决于顶点的顺序,这就是为什么你没有在下面明确引用它的原因。)



这可以归结为下面是一个简单的函数:

pre $ 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);
}

然后驱动程序计算网格的体积:

  public float VolumeOfMesh(Mesh mesh){
var vols =从mesh.Triangles中的t开始
选择SignedVolumeOfTriangle(t。 P1,t.P2,t.P3);
返回Math.Abs​​(vols.Sum());
}


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());
}

这篇关于如何计算三维网格物体的体积,三维网格物体的表面由三角形组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆