FILLPOLYGON3D Fill a 3D polygon specified by a list of vertex coords. fillPolygon3d(COORD, COLOR) packs coordinates in a single [N*3] array. COORD can also be a cell array of polygon, in this case each polygon is drawn using the same color. fillPolygon3d(PX, PY, PZ, COLOR) specifies coordinates in separate numeric vectors (either row or columns) fillPolygon3d(..., PARAM, VALUE) allows to specify some drawing parameter/value pairs as for the plot function. H = fillPolygon3d(...) also returns a handle to the list of created patch objects. Example t = linspace(0, 2*pi, 100)'; xt = 10 * cos(t); yt = 5 * sin(t); zt = zeros(100,1); poly = [xt yt zt]; figure; hold on; axis equal; fillPolygon3d(poly, 'c'); drawPolygon3d(poly, 'linewidth', 2, 'color', 'k'); See also polygons3d, drawPolygon3d, drawPolyline3d
0001 function varargout = fillPolygon3d(varargin) 0002 %FILLPOLYGON3D Fill a 3D polygon specified by a list of vertex coords. 0003 % 0004 % fillPolygon3d(COORD, COLOR) 0005 % packs coordinates in a single [N*3] array. 0006 % COORD can also be a cell array of polygon, in this case each polygon is 0007 % drawn using the same color. 0008 % 0009 % fillPolygon3d(PX, PY, PZ, COLOR) 0010 % specifies coordinates in separate numeric vectors (either row or 0011 % columns) 0012 % 0013 % fillPolygon3d(..., PARAM, VALUE) 0014 % allows to specify some drawing parameter/value pairs as for the plot 0015 % function. 0016 % 0017 % H = fillPolygon3d(...) 0018 % also returns a handle to the list of created patch objects. 0019 % 0020 % Example 0021 % t = linspace(0, 2*pi, 100)'; 0022 % xt = 10 * cos(t); 0023 % yt = 5 * sin(t); 0024 % zt = zeros(100,1); 0025 % poly = [xt yt zt]; 0026 % figure; hold on; axis equal; fillPolygon3d(poly, 'c'); 0027 % drawPolygon3d(poly, 'linewidth', 2, 'color', 'k'); 0028 % 0029 % See also 0030 % polygons3d, drawPolygon3d, drawPolyline3d 0031 % 0032 0033 % ------ 0034 % Author: David Legland 0035 % E-mail: david.legland@inrae.fr 0036 % Created: 2007-01-05 0037 % Copyright 2007-2024 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas 0038 0039 % Check if axes handle is specified 0040 if isAxisHandle(varargin{1}) 0041 hAx = varargin{1}; 0042 varargin(1) = []; 0043 else 0044 hAx = gca; 0045 end 0046 0047 % check case we want to draw several curves, stored in a cell array 0048 var1 = varargin{1}; 0049 if iscell(var1) 0050 hold on; 0051 h = []; 0052 for i = 1:length(var1(:)) 0053 h = [h; fillPolygon3d(hAx, var1{i}, varargin{2:end})]; %#ok<AGROW> 0054 end 0055 if nargout>0 0056 varargout{1}=h; 0057 end 0058 return; 0059 end 0060 0061 % extract vertex coordinates 0062 if min(size(var1)) == 1 0063 % if first argument is a vector (either row or column), then assumes 0064 % first argument contains x coords, second argument contains y coords 0065 % and third one the z coords 0066 px = var1; 0067 if length(varargin) < 3 0068 error('geom3d:fillPolygon3d:Wrong number of arguments in fillPolygon3d'); 0069 end 0070 py = varargin{2}; 0071 pz = varargin{3}; 0072 varargin = varargin(4:end); 0073 else 0074 % first argument contains all three coordinates 0075 px = var1(:, 1); 0076 py = var1(:, 2); 0077 pz = var1(:, 3); 0078 varargin = varargin(2:end); 0079 end 0080 0081 % extract color information 0082 if isempty(varargin) 0083 color = 'c'; 0084 else 0085 color = varargin{1}; 0086 varargin = varargin(2:end); 0087 end 0088 0089 % fill the polygon 0090 h = fill3(hAx, px, py, pz, color, varargin{:}); 0091 0092 if nargout>0 0093 varargout{1}=h; 0094 end