DRAWVERTICES Draw the vertices of a polygon or polyline. drawVertices(POLY) Draws the vertices of the given polygon, using pre-defined style. Default is to draw vertices as squares, with the first vertex filled. Example poly = circleToPolygon([20 30 40], 16); drawPolygon(poly); hold on; axis equal; drawVertices(poly); See also drawPoint, drawPolygon, drawPolyline ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-12-11, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function varargout = drawVertices(varargin) 0002 %DRAWVERTICES Draw the vertices of a polygon or polyline. 0003 % 0004 % drawVertices(POLY) 0005 % Draws the vertices of the given polygon, using pre-defined style. 0006 % Default is to draw vertices as squares, with the first vertex filled. 0007 % 0008 % Example 0009 % poly = circleToPolygon([20 30 40], 16); 0010 % drawPolygon(poly); 0011 % hold on; axis equal; 0012 % drawVertices(poly); 0013 % 0014 % See also 0015 % drawPoint, drawPolygon, drawPolyline 0016 % 0017 % ------ 0018 % Author: David Legland 0019 % e-mail: david.legland@grignon.inra.fr 0020 % Created: 2011-12-11, using Matlab 7.9.0.529 (R2009b) 0021 % Copyright 2011 INRA - Cepia Software Platform. 0022 0023 % extract handle of axis to draw on 0024 if isAxisHandle(varargin{1}) 0025 ax = varargin{1}; 0026 varargin(1) = []; 0027 else 0028 ax = gca; 0029 end 0030 0031 var = varargin{1}; 0032 0033 0034 %% Manage cell arrays of polygons / polylines 0035 0036 % case of a set of polygons stored in a cell array 0037 if iscell(var) 0038 N = length(var); 0039 h = zeros(N, 1); 0040 for i = 1:N 0041 state = ishold(gca); 0042 hold on; 0043 % check for empty polygons 0044 if ~isempty(var{i}) 0045 h(i) = drawVertices(ax, var{i}, varargin{2:end}); 0046 end 0047 if ~state 0048 hold off 0049 end 0050 end 0051 0052 if nargout > 0 0053 varargout = {h}; 0054 end 0055 0056 return; 0057 end 0058 0059 0060 %% Parse coordinates and options 0061 0062 % Extract coordinates of vertices 0063 if size(var, 2) > 1 0064 % first argument is a vertex array 0065 px = var(:, 1); 0066 py = var(:, 2); 0067 varargin(1) = []; 0068 0069 elseif length(varargin) >= 2 && isnumeric(varargin{1}) && isnumeric(varargin{2}) 0070 % arguments 1 and 2 correspond to x and y coordinate respectively 0071 px = varargin{1}; 0072 py = varargin{2}; 0073 varargin(1:2) = []; 0074 0075 else 0076 % unknow input format 0077 error('Should specify either a N-by-2 array, or 2 N-by-1 vectors'); 0078 end 0079 0080 % concatenate input argument(s) with default options 0081 defaults = {'MarkerSize', 6}; 0082 if length(varargin) == 1 0083 varargin = [varargin defaults]; 0084 else 0085 varargin = [{'ks'} defaults varargin]; 0086 end 0087 0088 0089 %% Draw the vertices 0090 0091 % draw the vertices 0092 h = plot(ax, px, py, varargin{:}); 0093 0094 % draw the first vertex with a different style 0095 plot(ax, px(1), py(1), 'ks', 'MarkerFaceColor', 'k', 'MarkerSize', 8); 0096 0097 % format output arg 0098 if nargout > 0 0099 varargout = {h}; 0100 end