how to find area and volume from a .stl file?
Show older comments
I need to find the area and volume of 3D triangulation. I used [F,V] = stlBinaryRead('DWB1.stl'); to read the file "DWB1.stl". But when I used stlBinaryRead.m to get volume, it gives NaN. Hot to fix this? I used V'( all( isnan( V' ), 2 ), : )) = (); to remove NaN. but did not work.
1 Comment
As far as I can tell, stlBinaryRead.m is not a part of base MATLAB, or any of its toolboxes. It's also not from any submission on the File Exchange or GitHub. In fact, the only mention of this file that I can find anywhere on the web is this thread. There are plenty of other binary STL file reader scripts and functions with similar names, but that doesn't tell us anything.
So you're using a function which ostensibly returns lists of face and vertex data, but somehow you got the function to return volume instead? If you're not getting volume from stlBinaryRead(), then you haven't told us how you're calculating it.
In sum, all we know is that you have an STL file, you did something with it, and you got NaN. Maybe it's a problem with stlBinaryRead() (what is it? is it being used correctly?). Maybe it's a problem with your STL file (is it binary? is it manifold?). Maybe it's a problem with whatever other calculations you're using that you aren't telling us about.
Say what tools you're using, show the actual code you're using and the actual errors you're getting, and attach the actual file that's being read (you'll probably have to zip it).
Accepted Answer
More Answers (1)
Your STL, like many scans, is not a closed surface, and it has defects. According to admesh, it has 180 disconnected edges and 70 degenerate faces. I'd guess that's enough to potentially cause problems. It also has 102188 redundant vertices, but I doubt those do anything other than make the file bigger.
Given that several of the people commenting on the stlVolume.m implementation suggest that it has problems, I would assume that's where to look. We might expect that it should return 0 volume as it does for other open surfaces, but with the number of degenerate faces creating cross-products of zero, the output will be NaN.
unzip DWB4.zip
% using the same reader
[F,V] = stlBinaryRead('DWB4.stl');
% use the modified tool, discarding contributions from degenerate faces
[totalVolume,totalArea] = stlVolume(V',F')
% display the thing
patchargs = {'facecolor',[1 1 1],'edgecolor','none'};
patch('faces',F,'vertices',V,patchargs{:})
% set up lighting, etc
az = 30;
l1 = lightangle(az,45);
l2 = lightangle(az+180,-45);
set(l1,'color',[1 0.9 0.3]);
set(l2,'color',[0.9 0.3 1]);
material dull
axis image
view(3)
grid on
That looks like the same volume returned by admesh.
3 Comments
Surya
on 19 Apr 2024
DGM
on 21 Apr 2024
Are you using the modified version of stlVolume() that I attached, or are you using the one you were using before?
I ran the same code on the other files, and these are the [volume, area] that I got:
% DWB4 [2383161 91950]
% DWB5 [2028928 83337]
% DWB8 [2246068 88991]
% DWB9 [2926249 103179]
% DWB10 [2658433 98833]
% DWB11 [3142772 109394]
Surya
on 22 Apr 2024
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!