Calculate the volume of a CAD part

10 views (last 30 days)
will davis
will davis on 20 May 2019
Commented: Rik on 20 May 2019
Is there a way that I can calcuate the volume and bounding box of an .STL file?

Answers (1)

Rik
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
will davis
will davis on 20 May 2019
I guess my question was a little vague. I've never worked with stl files in matlab before. I'm trying to write an algorithm that uses to the volume of a single CAD part saved as an STL. While I could use CAD software to find the volume and bounding volume, I would like to be able use a internal script in matlab to calculate the parts volume.
An example of a part could be the simple rubber duck in the link below:
Rik
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.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!