matGeom icon indicating copy to clipboard operation
matGeom copied to clipboard

Bug in minConvexHull ?

Open oqilipo opened this issue 7 years ago • 9 comments

Hi

I've tried minConvexHull, but I get a mesh with edges with two faces on one side. Here is the test case: test_minConvexHull.zip One of the bad edges is marked in red here: minconvexhull

Thanks in advance

oqilipo avatar Aug 09 '17 18:08 oqilipo

hi,

not really a bug, but the output of minConvexHull does not impose faces to have consistent orientation. This would be interesting, however... I think this can easily be added, as the result is convex. I check it...

dlegland avatar Aug 10 '17 13:08 dlegland

Hi,

I have just made a commit that should solve the problem. You can check result of face orientation with the following: pfaces = minConvexHull(vertices);
pFacesNormals = faceNormal(vertices, pfaces); pFacesCenters = faceCentroids(vertices, pfaces); figure; drawMesh(vertices, pfaces); title('min convex hull') axis equal; view(3); hold on ; drawVector3d(pFacesCenters, pFacesNormals)

Hope this solves the problem?

dlegland avatar Aug 10 '17 14:08 dlegland

Thank you,

I will evalute it and give feedback.

oqilipo avatar Aug 11 '17 21:08 oqilipo

There is still an error, if you remove the last vertex of the testVertices.mat from above :

load('testVertices')
% Delete last vertex
vertices(end,:)=[];
% Check if all vertices are unique
assert(length(vertices)==length(unique(vertices,'rows')))
% Convex hull
faces = minConvexHull(vertices);
% Triangulate
faces = triangulateFaces(faces);
% Visualization
figure('Color','w'); view(3); axis equal tight
patch('Vertices',vertices,'Faces',faces,'FaceColor','none')
% Edges
edges = meshEdges(faces);
% Edge faces
edgeFaces = meshEdgeFaces(vertices, edges, faces);
Error using meshEdgeFaces/processFace (line 69)
Two faces were found on left side of edge 1100

Thanks in advance

oqilipo avatar Sep 12 '17 18:09 oqilipo

Hi, thanks for reporting. I will investigate this ASAP...

dlegland avatar Sep 13 '17 14:09 dlegland

Hi, I just had a look, and could not reproduce the bug... Is it still up to date?

dlegland avatar May 17 '19 07:05 dlegland

I'll check it

oqilipo avatar May 17 '19 07:05 oqilipo

Seems to work.

However, one should be aware that unreferenced vertices can remain:

load('testVertices')
mesh.vertices=vertices;
% Delete last vertex
mesh.vertices(end,:)=[];
% Check if all vertices are unique
assert(length(mesh.vertices)==length(unique(mesh.vertices,'rows')))
% Convex hull
mesh.faces = minConvexHull(mesh.vertices);
% Triangulate
mesh.faces = triangulateFaces(mesh.faces);
% Stats
disp(['No of components: ' num2str(numel(splitMesh(mesh)))])
trimmedMesh=trimMesh(mesh);
disp(['No of unreferenced vertices: ' num2str(size(mesh.vertices,1)-size(trimmedMesh.vertices,1))])
disp(['No of components of the trimmed mesh: ' num2str(numel(splitMesh(trimmedMesh)))])
No of components: 3
No of unreferenced vertices: 3
No of components of the trimmed mesh: 1

oqilipo avatar May 21 '19 18:05 oqilipo

Hi, thanks for checking! I agree, the function can be more informative about deletion of vertices. I'll check it.

dlegland avatar May 23 '19 20:05 dlegland