File Exchange

image thumbnail

Volume of a surface triangulation

version (1.43 KB) by Krishnan Suresh
Given a surface triangulation, compute the volume enclosed using divergence theorem.


Updated 17 Mar 2010

View License

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

Cite As

Krishnan Suresh (2021). Volume of a surface triangulation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)


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

Dwayne Bourgoyne

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.

Vikas Kurapati

Can't understand how to run this and what format the input should be and what is n from the triangulation.

Marina Matos


Somebody can help me to running this function, I can´t, please.


Lorenzo Luciano


Hej Suresh,

Thank you for your inputs. I think it is equally suitable calculating volume of triangular patches of isosurfaces?

I look forward hearing from you.

Pinaki Bhattacharya

Cool application.

Marc Lalancette

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


Dimid Duchovny




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.

Matt Kindig

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.

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!