title: How do I calculate the volume of an object stored in STL files?
body: <p>I have .stl (<a href="http://en.wikipedia.org/wiki/STL_(file_format)" rel="noreferrer">STL is a file format native to the stereolithography CAD software created by 3D Systems</a>) files, from which I must calculate the volume. How do I do this? I'm using the calculation below but the volume is not equal to that calculated by other software</p>
  
  <pre><code>float x1,y1,z1;
  float x2,y2,z2;
  float x3,y3,z3;
  </code></pre>
  
  <p>The above are the vertices. <code>triangles</code> is just a data structure holding an object with the vertices of each triangle.</p>
  
  <pre><code>totalVolume += currentVolume = 
  (triangles[i].x1*triangles[i].y2*triangles[i].z3 - 
  triangles[i].x1*triangles[i].y3*triangles[i].z2 -
  
  triangles[i].x2*triangles[i].y1*triangles[i].z3 + 
  triangles[i].x2*triangles[i].y3*triangles[i].z1 + 
  triangles[i].x3*triangles[i].y1*triangles[i].z2 - 
  triangles[i].x3*triangles[i].y2*triangles[i].z1) / 6;
  </code></pre>
  
  <p>Do you also involve the calculation with the normal vector?</p>