MATLAB: Calculate the Volume of a Concave Polyhedron from Many Scattered 3D Points
I have 20 to 30 randomly generated 3D points in the form of vertices from which a polyhedron is defined. I tried to use DelaunayTri(points)
to enumerate faces and use the cross product determinant to calculate and sum tetrahedral volumes, but I'm not sure if it works great for polyhedra that are not convex.
Also, how can such a concave body be constructed?
+3
source to share
1 answer
Thanks to Mike Garrity of MATLAB Answers ™
alphaShape
similar to convhull
but more general. This will create non-convex shapes.
Point cloud of points:
npts = 75;
pts = randn(npts,3);
scatter3(pts(:,1),pts(:,2),pts(:,3),'filled')
shp = alphaShape(pts);
h = plot(shp);
Alpha shape plot:
Alpha Shape Volume:
volume(shp) ans = 27.3914
Another way to indicate other points within the shape (in green):
testpts = randn(150,3);
inmask = inShape(shp,testpts);
h.FaceColor = [.75 .75 .75];
h.FaceAlpha = .25;
hold on
scatter3(testpts(inmask,1),testpts(inmask,2),testpts(inmask,3),'.','MarkerEdgeColor','green')
scatter3(testpts(~inmask,1),testpts(~inmask,2),testpts(~inmask,3),'.','MarkerEdgeColor','red')
+1
source to share