Calculate the volume of a CAD part
10 views (last 30 days)
Show older comments
Is there a way that I can calcuate the volume and bounding box of an .STL file?
0 Comments
Answers (1)
Rik
on 20 May 2019
An example to work with would make this easier to answer.
The bounding box should be fairly straightforward: just take the min and max of all your vertices for each coordinate.
Depending on the geometry of your model calculating the volume is either almost trivial, or extremely difficult. If your model is only convex you can use a point inside your mesh and calculate the volume of each tetrahedron. I believe there is a FEX submission that does that, so if you have a convex shape, I will look it up for you.
2 Comments
Rik
on 20 May 2019
That rubber duck isn't actually simple. It contains a lot of concave parts, making volume calculations difficult.
STL files contain two arrays of information: faces (generally triplets of vertex IDs) and vertices (coordinate points, generally xyz). Once you have loaded that into Matlab (reading as text file works well enough), you can do further processing.
It seems someone else did the hard work already: the mesh2tetra function from the FEX should help you separate your model into tetrahedra.
Does this help? Or do you have questions about how to read your specific stl to a format that functions like patch and mesh2tetra like to work with? I could look up some functions that can help you along there.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!