Hello Friends,
I want to calculate the volume of a 3D mesh object having a surface made up triangles. Could you help me.
Thank in advance Best Regards.
Can
Hello Friends,
I want to calculate the volume of a 3D mesh object having a surface made up triangles. Could you help me.
Thank in advance Best Regards.
Can
The GNU Triangulated Surface Library can do this for you. Keep in mind that the surface must be closed. That is not going to be the case for quite a few 3D models.
If you want to implement it yourself, you could start by taking a look at their code.
If I understand you correctly, you're saying you have a surface mesh of triangles already, and you'd like to generate a 3D solid mesh from it.
Triangles mean that you'll have to use tetrahedral elements for the 3D interior. You'll want to search for an octree auto meshing algorithm that can take a surface mesh as a seed.
This is a common problem in the finite element auto meshing literature. I'd look there.
Reading http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf, this 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());
}
Matlab code can be found here:
http://www.advancedmcode.org/volume-enclosed-by-a-triangulated-surface.html