0

I am trying to parse wavefront .obj file. From wikipedia I learned it's format specification. I am interested in volume analysis. Before that i worked in .stl files. I can compute volume of tetrahedron by using dot and cross product. In .stl files triangular faces' coordinates are given i.e.

  • point1(x1, y1, z1),
  • point2(x2, y2, z2),
  • point3(x3, y3, z3).

But in wavefront .obj files : Each face can contain three or more vertices. f v1 v2 v3 v4 ..... like this. I do not know how to calculate the volume now. Because my understanding is, it will produce a polyhedron. Any idea will be extremely helpful. Thanks!

run_time_error
  • 697
  • 1
  • 8
  • 22
  • I implemented the solution presented in this post and it works fine: http://stackoverflow.com/questions/1406029/how-to-calculate-the-volume-of-a-3d-mesh-object-the-surface-of-which-is-made-up – Nic Aug 29 '16 at 13:58
  • @Nic I also looked at the very post. In fact it is a famous one. But my problem is not about calculating triangular faced object's volume, Rather non-planer shaped object's volume consisting more than 3 points. Hence not triangle. – run_time_error Aug 30 '16 at 16:01

1 Answers1

2

Each polygonal face can be subdivided in triangles and therefore used for tetrahedrons. If you are lucky enough, you can find polygons with 4 vertices only (easy to be decomposed in two triangles on the fly). For polygons with more than 4 vertices you need a triangulation algorithm to decompose the planar polygon in triangles. You can check Ear Clipping for example.

abenci
  • 8,422
  • 19
  • 69
  • 134
  • Following your link and couple of more google search i found a code snippet. vertex v1, v2, v3; vector newtris; v1 = polygon.vertices[0]; for ( i=0; i < polygon.sides-2; ++i ) { v2=polygon.vertices[ i+1 ]; v3=polygon.vertices[ i+2 ]; newtris.push_back( triangle( v0, v1, v2 ) ); } This should work, right ? – run_time_error Aug 26 '16 at 10:41
  • 1
    Polygon can have many vertices and be non-convex. This is why a recommended a triangulator. – abenci Aug 26 '16 at 13:51