www.pudn.com > lianma.rar > connectpoly.m, change:2004-12-16,size:1040b


function c = connectpoly(x, y) 
%CONNECTPOLY Connects vertices of a polygon. 
%   C = CONNECTPOLY(X, Y) connects the points with coordinates given 
%   in X and Y with straight lines. These points are assumed to be a 
%   sequence of polygon vertices organized in the clockwise or 
%   counterclockwise direction. The output, C, is the set of points 
%   along the boundary of the polygon in the form of an nr-by-2 
%   coordinate sequence in the same direction as the input. The last 
%   point in the sequence is equal to the first. 
 
%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins 
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004 
%   $Revision: 1.4 $  $Date: 2003/11/21 14:29:16 $ 
 
v = [x(:), y(:)]; 
 
% Close polygon. 
if ~isequal(v(end, :), v(1, :)) 
   v(end + 1, :) = v(1, :); 
end 
 
% Connect vertices. 
segments = cell(1, length(v) - 1); 
for I = 2:length(v) 
   [x, y] = intline(v(I - 1, 1), v(I, 1), v(I - 1, 2), v(I, 2)); 
   segments{I - 1} = [x, y]; 
end 
 
c = cat(1, segments{:});