FILLPOLYGON Fill a polygon specified by a list of points. fillPolygon(POLY); Fills the interior of the polygon specified by POLY. The boundary of the polygon is not drawn, see 'drawPolygon' to do it. POLY is a single [N*2] array. If POLY contains NaN-couples, each portion between the [NaN;NaN] will be filled separately. fillPolygon(PX, PY); Specifies coordinates of the polygon in separate arrays. H = fillPolygon(...); Also returns a handle to the created patch Example oRectangle = [0 0;10 0;10 10;0 10]; iRectangle = flipud(0.5*oRectangle+1); pol = {oRectangle, iRectangle}; figure('color','w') fillPolygon(pol,'g') drawPolygon(pol,'r') See also polygons2d, drawCurve, drawPolygon
0001 function varargout = fillPolygon(varargin) 0002 %FILLPOLYGON Fill a polygon specified by a list of points. 0003 % 0004 % fillPolygon(POLY); 0005 % Fills the interior of the polygon specified by POLY. The boundary of 0006 % the polygon is not drawn, see 'drawPolygon' to do it. 0007 % POLY is a single [N*2] array. 0008 % If POLY contains NaN-couples, each portion between the [NaN;NaN] will 0009 % be filled separately. 0010 % 0011 % fillPolygon(PX, PY); 0012 % Specifies coordinates of the polygon in separate arrays. 0013 % 0014 % H = fillPolygon(...); 0015 % Also returns a handle to the created patch 0016 % 0017 % Example 0018 % oRectangle = [0 0;10 0;10 10;0 10]; 0019 % iRectangle = flipud(0.5*oRectangle+1); 0020 % pol = {oRectangle, iRectangle}; 0021 % figure('color','w') 0022 % fillPolygon(pol,'g') 0023 % drawPolygon(pol,'r') 0024 % 0025 % 0026 % See also 0027 % polygons2d, drawCurve, drawPolygon 0028 0029 % ------ 0030 % Author: David Legland, oqilipo 0031 % E-mail: david.legland@inrae.fr 0032 % Created: 2005-04-07 0033 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE 0034 0035 % Check input 0036 if isempty(varargin) 0037 error('Not enough input arguments.'); 0038 end 0039 0040 % Check if the polygon is given in two separate arrays. 0041 if numel(varargin) > 1 0042 if isnumeric(varargin{2}) 0043 varargin{2} = [varargin{1}, varargin{2}]; 0044 varargin(1)=[]; 0045 end 0046 end 0047 0048 % Convert into a polyShape 0049 polyShape = parsePolygon(varargin{1}, 'polyshape'); 0050 varargin(1)=[]; 0051 0052 % Set default color format if no color is given. 0053 if isempty(varargin) 0054 varargin = {'FaceColor', 'b'}; 0055 end 0056 0057 if ~mod(numel(varargin), 2) == 0 0058 % Assume only the color was given. 0059 varargin = ['FaceColor', varargin]; 0060 end 0061 0062 % Fill the polygon with desired style. 0063 h = plot(polyShape, varargin{:}, 'LineStyle', 'none'); 0064 0065 % Output 0066 if nargout > 0 0067 varargout{1} = h; 0068 end