2.33333

2.3 | 3 ratings Rate this file 11 downloads (last 30 days) File Size: 2.09 KB File ID: #15221

triangulationVolume

by Jeroen Verbunt

 

06 Jun 2007 (Updated 05 Sep 2007)

No BSD License  

Compute volume and area of triangulation using divergence theorem of Gauss

Download Now | Watch this File

File Information
Description

Computes the VOLUME and AREA of a closed surface defined by the triangulation in indices TRI and coordinates X, Y and Z, using the divergence theorem of Gauss (volume/surface integral). The unit of the volume equals to UNIT^3 and the unit of the area equals to UNIT^2, with UNIT the unit of the coordinates X,Y,Z. The surface needs to be closed, this is not checked.
See example in testTriangulationVolume.m

MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files triangulationVolume.m,
testTriangulationVolume.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
11 Jun 2007 Matt K.

Is there a sample dataset you can provide to verify the calculations?

I got the Area calculation to work for a unit sphere, however the Volume calculation gave me a 'Nan' result.

I too have used the Div. Theorm. to calculate volume of a triangular mesh, albeit differently. This is a clipping from my program:

Mtot=0;
rho=1;
T=(3-by-n set of your x,y,z data points)
tri=(m-by-num_elements mesh connectivity matrix)
for i=1:num_elements
    % Get verticies of element
    verts=tri(i,:);
    % Get 3d coords of points on element
    p1=T(:,verts(1));
    p2=T(:,verts(2));
    p3=T(:,verts(3));
    A=[p1 p2 p3];
    
    % Calculate Mass of individual tetrahedron
    M(i)=rho*det(A)/6;
    
    % Calculate total mass of volume;
    Mtot=Mtot+M(i);
end

Also, I do not take the absolute value of my volume since I verify the direction of the normals to point out of the volume prior to calculation (not shown in above program)

Check out: http://www.avidaerospace.com/publications/SAWEPaper2005_OhanianPart1.pdf

25 Nov 2008 nor ki

there are diffrent results when you translate your vertices, which is unlikely for the volume...

30 Apr 2009 Edward Bender

I think I found a way to fix the code. On the line where Gauss' law is used:

vol = vol + abs(P(1) * N(1) * a);

The absolute value there is not correct and should be removed - when the vector field and normal vector are antiparallel the addition to the volume needs to be negative. With the current implementation you can change the volume by shifting the X coordinate. If you get rid of the absolute value everything is fine, so long as you can ensure that the normals on the surface point OUT. Although the addition of the absolute value seems intuitive, it is not how Gauss's law works.

The normals can be computed with another code on the filie exchange: computeNormalVectorTriangulation by David Gingras. David's code will give you normals that point outwards so long as the triangles are defined in a certain way... Refer to his code.

This update seems to give the right volume and remove the dependence on translation of vertices, at least in my testing.
 
-Ed

Please login to add a comment or rating.
Updates
05 Sep 2007

Added a simple example to test the code.

Tag Activity for this File
Tag Applied By Date/Time
linear algebra Jeroen Verbunt 22 Oct 2008 09:14:43
triangulation Jeroen Verbunt 22 Oct 2008 09:14:43
volume Jeroen Verbunt 22 Oct 2008 09:14:43
area Jeroen Verbunt 22 Oct 2008 09:14:43
divergence Jeroen Verbunt 22 Oct 2008 09:14:43
gauss Jeroen Verbunt 22 Oct 2008 09:14:43

Contact us at files@mathworks.com