akuukka / quickhull

C++ implementation of the 3D QuickHull algorithm
266 stars 52 forks source link

How do you get the triangles? #2

Closed Bk8 closed 7 years ago

Bk8 commented 7 years ago

I am trying to get the coordinates of each triangle like this: vertexBuffer[indexBuffer[i]].x

but I get wrong triangulations.

Bk8 commented 7 years ago

Something is wrong, when I get the size_t triangleCount = indBuf.size()/3; with these points:

p1 x: 0.000000 y: 0.000000 z: 3.000000 p2 5.000000 0.000000 3.000000

p3 5.000000 0.000000 0.000000 p4 0.000000 0.000000 0.000000

Im getting a triangle count of 4, an its just a plane formed by 4 points it should be 2.

akuukka commented 7 years ago

I'll have a look... But note that quickhull always returns a proper closed triangle mesh with volume, even if the given point cloud is on a plane or line. Still, 4 triangles is not the correct answer here.

Bk8 commented 7 years ago

Ok thanks for the reply.

akuukka commented 7 years ago

Alright, checked the output and it turned out to be correct.

If you modify your point cloud's third point to be (5,1,0) and inspect the output, you see that the original output mesh is just zero-volume version of the same tetrahedron.

Until #1 was fixed, QuickHull did indeed output planar triangle meshes in cases such as yours. But that approach has a problem: results become very unpredictable. If you start with your original point cloud with third point's y component set to 1 and then iteratively make it smaller and smaller, then at some point the output mesh would abruptly stop being a tetrahedron and become a totally different kind of mesh.

Bk8 commented 7 years ago

Now I see, thanks for your time!!!.