Calculates the volume of a point-face triangel mesh.
points=[[0,0,0], ... ]
faces=[[0,1,2],[0,2,3],[4,6,5],[4,7,6],
[0,4,5],[1,0,5],[1,5,6],[2,1,6],
[2,6,7],[2,7,3],[3,7,4],[3,0,4]]
function meshVolume(points,faces)=
let(
sum=[for(faces)-1]*[for(f=faces)
SignedVolumeOfTriangle(points[f[0]],points[f[1]],points[f[2]])])
sum
;
function SignedVolumeOfTriangle( p1, p2, p3) =
let(
v321 = p3.x*p2.y*p1.z,
v231 = p2.x*p3.y*p1.z,
v312 = p3.x*p1.y*p2.z,
v132 = p1.x*p3.y*p2.z,
v213 = p2.x*p1.y*p3.z,
v123 = p1.x*p2.y*p3.z
) (1.0/6.0)*(-v321 + v231 + v312 - v132 - v213 + v123);
Saturday, December 19, 2020
Volume of mesh
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment