K
K
kid-programmer2014-09-25 16:56:14
JavaScript
kid-programmer, 2014-09-25 16:56:14

How to calculate volume?

There is a .stl file, it contains information about a three-dimensional model, how to calculate the volume? Is there any way to work with such files (preferably in js or C#). I don't understand 3d at all. I would be grateful for any information on the topic.

solid cube
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 0 1 0
       vertex 1 1 0
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 1 1 0
       vertex 1 0 0
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 0 0 1
       vertex 0 1 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 0 1 1
       vertex 0 1 0
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 1 0 0
       vertex 1 0 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 0
       vertex 1 0 1
       vertex 0 0 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 1
       vertex 1 0 1
       vertex 1 1 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 0 1
       vertex 1 1 1
       vertex 0 1 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 1 0 0
       vertex 1 1 0
       vertex 1 1 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 1 0 0
       vertex 1 1 1
       vertex 1 0 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 1 0
       vertex 0 1 1
       vertex 1 1 1
     endloop
   endfacet
   facet normal 0 0 0
     outer loop
       vertex 0 1 0
       vertex 1 1 1
       vertex 1 1 0
     endloop
   endfacet
 endsolid cube

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mrrl, 2014-10-02
@kid-programmer

It is enough for each face
vertex x1 y1 z1
vertex x2 y2 z2
vertex x3 y3 z3 to
calculate the value Vj=(x1*(y2*z3-y3*z2)+x2*(y3*z1-y1*z3)+x3*(y1* z2-y2*z1))/6, and find the sum of these values ​​(some of them will be negative, but that's okay). For a closed model, it will be the desired volume.
It is easier to work with binary STL - there is no need to spend effort on parsing.

F
Faraday, 2014-10-02
@Faraday

If the vertices are known, then the volume of the convex hull can be calculated. This can be done manually, or Wolfram Mathematica can do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question