1、命令模块一:% Create a set of points representing the point cloudnumpts = 192;t = linsp锾攒揉敫ace( -pi, pi, numpts+1 )';t(end) = [];r = 0.1 + 5*sqrt( cos( 6*t ).^2 + (0.7).^2 );x = r.*cos(t);y = r.*sin(t);ri = randperm(numpts);x = x(ri);y = y(ri);
2、命令模块二:% Construct a Delaunay Triangulation of the point set.dt = delaunayTriangulation(x,y);tri = dt(:,:);
3、命令模块三:% Insert the location of the Voronoi vertices into the existing% triangulationV = dt.voronoiDiagram();% Remove the infinite vertexV(1,:) = [];numv = size(V,1);dt.Points(end+(1:numv),:) = V;
4、警告:已检测到重复的数据点并将其删除。相对于delaunayTriangulation属性X中的唯一点集定义了Triangulation索引。
5、命令模块四:% The Delaunay edges that connect pairs of sample points repres髫潋啜缅ent the% boundary.delEdges = dt.edges();validx = delEdges(:,1) <= numpts;validy = delEdges(:,2) <= numpts;boundaryEdges = delEdges((validx & validy), :)';xb = x(boundaryEdges);yb = y(boundaryEdges);clf;triplot(tri,x,y);axis equal;hold on;plot(x,y,'*r');plot(xb,yb, '-r');xlabel('Curve reconstruction from a point cloud', 'fontweight','b');hold off;
6、按“Enter”键。如图1所示。