Home > matGeom > geom3d > fillPolygon3d.m

fillPolygon3d

PURPOSE ^

FILLPOLYGON3D Fill a 3D polygon specified by a list of vertex coords.

SYNOPSIS ^

function varargout = fillPolygon3d(varargin)

DESCRIPTION ^

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(1,100);
     figure; fillPolygon3d(xt, yt, zt, 'c');
 
   See Also:
   polygons3d, drawPolygon3d, drawPolyline3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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(1,100);
0025 %     figure; fillPolygon3d(xt, yt, zt, 'c');
0026 %
0027 %   See Also:
0028 %   polygons3d, drawPolygon3d, drawPolyline3d
0029 %
0030 
0031 % ------
0032 % Author: David Legland
0033 % e-mail: david.legland@inra.fr
0034 % Created: 2007-01-05
0035 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.
0036 
0037     
0038 % check case we want to draw several curves, stored in a cell array
0039 var1 = varargin{1};
0040 if iscell(var1)
0041     hold on;
0042     h = [];
0043     for i = 1:length(var1(:))
0044         h = [h; fillPolygon3d(var1{i}, varargin{2:end})]; %#ok<AGROW>
0045     end
0046     if nargout>0
0047         varargout{1}=h;
0048     end
0049     return;
0050 end
0051 
0052 % extract vertex coordinates
0053 if min(size(var1)) == 1
0054     % if first argument is a vector (either row or column), then assumes
0055     % first argument contains x coords, second argument contains y coords
0056     % and third one the z coords
0057     px = var1;
0058     if length(varargin) < 3
0059         error('geom3d:fillPolygon3d:Wrong number of arguments in fillPolygon3d');
0060     end
0061     py = varargin{2};
0062     pz = varargin{3};
0063     varargin = varargin(4:end);
0064 else
0065     % first argument contains all three coordinates
0066     px = var1(:, 1);
0067     py = var1(:, 2);
0068     pz = var1(:, 3);
0069     varargin = varargin(2:end);
0070 end
0071 
0072 % extract color information
0073 if isempty(varargin)
0074     color = 'c';
0075 else
0076     color = varargin{1};
0077     varargin = varargin(2:end);
0078 end
0079 
0080 % fill the polygon
0081 h = fill3(px, py, pz, color, varargin{:});
0082 
0083 if nargout>0
0084     varargout{1}=h;
0085 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019