matGeom
matGeom copied to clipboard
Bug in minConvexHull ?
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:
Thanks in advance
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...
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?
Thank you,
I will evalute it and give feedback.
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
Hi, thanks for reporting. I will investigate this ASAP...
Hi, I just had a look, and could not reproduce the bug... Is it still up to date?
I'll check it
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
Hi, thanks for checking! I agree, the function can be more informative about deletion of vertices. I'll check it.