Silhouette outline of polygon surface
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to get the outline of a triangulated 3D surface projected onto the XY plane. Here's an example. First, let's get a triangulated faces/vertices surface into FV:
xyz = [5, 2, 6, 0, 3; 0, 2, 4, 2, 1; 5, 6, 6, 7, 9]';
tri = [1, 2, 4; 1, 5, 4; 1, 2, 5; 2, 3, 5; 2, 4, 3; 3, 4, 5] ;
FV = struct('faces',tri,'vertices',xyz);
figure, patch(FV,'FaceColor','c','FaceAlpha',0.95), hold on
Now, if this surface were convex, I could simply take the convex hull of the XY coordinates of all the outline outXY points:
k = convhull(FV.vertices(:,1:2));
outXY = FV.vertices(k,1:2);
plot(outXY(:,1),outXY(:,2),'.r-','LineWidth',6), axis equal
However, of course, I want to work with non-convex surfaces :) Notice the little patch of white where the convex hull didn't follow the "outline" of my blue patch?
I can imagine a relatively simple hack, where I would just make a solid colour patch similar to this figure, take a screenshot using getframe() then use bwboundaries() on a segmentation of the figure window image.
I'm just trying to work out if there's a nifty trick that would provide an exact result. Votes will be given for good ideas about the approach, even if no code is involved. For instance, the freeBoundary method of delaunay triangulations might be related here, but I can't work out how to reduce my 3d triangulation into a 2d triangulation (which will have overlapping triangles) in a way that freeBoundary() is actually useful.
Note, for the moment, let's just say that I'm not interested in internal holes, such that a doughnut surface would simply return the outline of the outer circle (similar to the 'noholes' option of bwboundaries).
Thanks, Sven.
6 comentarios
Respuesta aceptada
Sean de Wolski
el 21 de Mzo. de 2013
Here is what I came up with:
%%Sean's try
% Here's the general approach:
%
% # Calculate the Delaunay Triangulation in three dimensions to create
% tetrahedra forming the shape.
% # Use the x and y coordinates of this triangulation to build two
% dimensional polygons irrespective of Z.
% # Calculate the union of all of these two dimensional polygons to get the minimal
% bounding polygon.
%
% 03/21/2013
%%Original Data
xyz = [5, 2, 6, 0, 3; 0, 2, 4, 2, 1; 5, 6, 6, 7, 9]';
tri = [1, 2, 4; 1, 5, 4; 1, 2, 5; 2, 3, 5; 2, 4, 3; 3, 4, 5] ;
FV = struct('faces',tri,'vertices',xyz);
%%Delaunay Triangulation
tri3 = triangulation(tri,xyz);
%%Engine:
% Disable warning since we don't need anything depending on CW v. CCW
warning('off','map:polygon:noExternalContours');
% Initialize final polygon vectors
px = [];
py = [];
% Unionize each polygon with the group using |polybool()| from Mapping
% Toolbox
for ii = 1:size(tri3.ConnectivityList,1)
[px, py] = polybool('union',...
tri3.Points(tri3.ConnectivityList(ii,:),1),...
tri3.Points(tri3.ConnectivityList(ii,:),2),...
px,py);
end
%%Visualize and Compare:
figure;
patch(FV,'FaceColor','c','FaceAlpha',0.95);
line(px,py,zeros(size(px)),'color','r','LineWidth',3)
view(2); % How did we do?
title('Woohoo!');
5 comentarios
Sean de Wolski
el 22 de Mzo. de 2013
Editada: Sean de Wolski
el 22 de Mzo. de 2013
Also, as far as having all of this knowledge about the structure, I was originally wondering about using this to do a constrained Delaunay triangulation forcing us to only get the triangles that make up this z-buffered shape.
After a playing with it and thinking about it more, I became more and more convinced that it would never work.
Más respuestas (0)
Ver también
Categorías
Más información sobre Computational Geometry en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!