# Calculate the volume of a CAD part

22 ビュー (過去 30 日間)
will davis 2019 年 5 月 20 日
コメント済み: Rik 2019 年 5 月 20 日
Is there a way that I can calcuate the volume and bounding box of an .STL file?

### 回答 (1 件)

Rik 2019 年 5 月 20 日
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 件のコメント

will davis 2019 年 5 月 20 日
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 2019 年 5 月 20 日
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.