Given a surface triangulation, compute the volume enclosed using divergence theorem.
Assumption:Triangle nodes are ordered correctly, i.e.,computed normal is outwards
Input: p: (3xnPoints), t: (3xnTriangles)
Output: total volume enclosed, and total area of surface
Krishnan Suresh (2021). Volume of a surface triangulation (https://www.mathworks.com/matlabcentral/fileexchange/26982-volume-of-a-surface-triangulation), MATLAB Central File Exchange. Retrieved .
The volume computed by the function is not right for some cases, and is right for other cases. If the bounding volume can be a convex hull, using the following MATLAB built-in functions to get the right volumes:
% suppose P is a (n by 3) coordinates matrix of some 3D space points, and coordinates of each row are in the order of (x,y,z)
DT = delaunayTriangulation(P(:,1),P(:,2),P(:,3));
[K,v] = convexHull(DT);
% then v is right volume
The volume calculation does not appear correct. Application of the divergence theorem to general tri-mesh volumes would be much more involved than a few lines of code. I recommend you run some test cases (eg, a sphere) before using. Area looks correct.
Can't understand how to run this and what format the input should be and what is n from the triangulation.
Somebody can help me to running this function, I can´t, please.
Thank you for your inputs. I think it is equally suitable calculating volume of triangular patches of isosurfaces?
I look forward hearing from you.
Nice application, but here's a cleaned up version (with V = p' and F = f'):
% 'z' coordinate of triangle centers.
FaceCentroidZ = ( V(F(:, 1), 3) + V(F(:, 2), 3) + V(F(:, 3), 3) ) /3;
% Face normal vectors, with length equal to triangle area.
FNdA = cross( (V(F(:, 2), :) - V(F(:, 1), :)), ...
(V(F(:, 3), :) - V(F(:, 2), :)) , 2 ) / 2;
% Volume from divergence theorem (using vector field along z).
V = FaceCentroidZ' * FNdA(:, 3);
Thanks a lot. I have difficult running the code. My input value representing the number of facets if presented in EXCEL file. How can I get the volume and surface area?
Ur response is apprecied in advance.
Thanks! This is exactly what I needed!
One thing: I wonder what happens if the volume is not closed? It might be nice if an open volume returned NaN or threw an error or something.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!