- Load the STL File: Use a suitable STL file reading function in MATLAB to import the geometry. MATLAB's “stlread” function is commonly used for this purpose.
- Compute Bounding Box: Calculate the minimum and maximum values along each dimension (x, y, z) of the vertices. These values define the bounding box that contains the part.
- Calculate Volume: With the dimensions of the bounding box, you can calculate its volume using the formula for a rectangular box.
Extract information from .stl file
13 次查看(过去 30 天)
显示 更早的评论
Hello everyone.
I'm trying to extract some information from a generic .stl file, what I'm trying to obtain is the volume of the "outbox" of the part (the volume of the box that contains the part). I'm having a bit of problem with finding these information with some matlab plugins.
Thank you in advance.
0 个评论
回答(2 个)
Vidip Jain
2023-8-31
I understand you want to extract information from a generic STL (Stereolithography) file and calculate the volume of the "outbox" of a part (bounding box)
You can follow these general steps using MATLAB:
Refer to this documentation for more information: https://www.mathworks.com/help/matlab/ref/stlread.html
0 个评论
DGM
2025-4-5,18:52
For example:
unzip sphere_20.stl.zip
% a sphere with a radius of 15
T = stlread('sphere_20.stl');
% get the bounding box and volume
extents = [min(T.Points,[],1); max(T.Points,[],1)]
bbvolume = prod(diff(extents,1,1))
% display it using patch()
patch('faces',T.ConnectivityList,'vertices',T.Points, ...
'facecolor','w','edgecolor','k');
view(3); camlight; view(10,33)
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
Obviously, the volume of the box depends on the orientation of the object (and its vertices) with respect to the coordinate axes. Consequently, despite the radii of the vertices being 15, the apparent diameter of the sphere is <30.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!