MATLAB: How to calculate the volume of a 3D triangular mesh

3dmeshvector

I have a pyramid with these vertices (each side is a triangle):
[-4 0 5;
1 -5 5;
1 0 1;
1 5 5;
1 0 0]
How can I calculate it's volume?
I couldn't quite understand this answer.

Best Answer

Untitled1.png
Not quite sure I understood the problem. Yet, a hunch:
vertices = [-4 0 5;
1 -5 5;
1 0 1;
1 5 5;
1 0 0];
g = []; N = [];
for k = 1:size(vertices,1)
g = [g, sum(vertices(k,:))/3];
a = abs(vertices(k,1)-vertices(k,2));
b = abs(vertices(k,1)-vertices(k,3));
N = [N, a*b*sin(pi/3)]; % assuming theta = pi/3
end
Volume = sum(g.*N)/6;