function fillpoints(varargin)
%   fillpoints(P1,P2,...,Pn,color) 
%   fillpoints([P1,P2,...,Pn],color) 
% plots 2D or 3D polygon given by points P1,P2,...,Pn which are *COLUMN* vectors of length 2 or 3
%   color can be 'r','g','b' etc. (see help for plot) or RGB color such as [1,1,0] 
%   for 3D polygon the points should be contained in the same plane
%
% You can get different styles by using an additional argument:
%   fillpoints([P1,P2,...,Pn],'o') 
%      plots the points as small circles, and does not connect them,
%   fillpoints([P1,P2,...,Pn],'r*:') 
%      plots the points as red stars, and connects them with a dotted line.
% Type   help plot   for more options.
%
% Examples
%   fillpoints([1;2],[3;4],[2;1],'r')        % plot red triangle with vertices (1,2),(3,4),(2,1)   
%   fillpoints([1;2],[3;4],[2;1],'ro-','LineWidth',2) % mark points with o, thick line
%   fillpoints([1;2;3],[3;4;1],[2;1;0],'g'); nice3d 
%                               % green triangle with vertices (1,2,3), (3,4,1), (2,1,0) 

% scan arguments until we find string or end
for k=1:nargin
  if isstr(varargin{k})
    k = k - 1;                % varargin{k} is last nonstring argument
    break
  end
end
if k == 0
  error('first argument has to be vector or matrix')
end
pts = horzcat(varargin{1:k}); pts = double(pts);
d = size(pts,1);
if d==2
  fill(pts(1,:),pts(2,:),varargin{(k+1):end});
elseif d==3
  fill3(pts(1,:),pts(2,:),pts(3,:),varargin{(k+1):end});
else
  error('columns must have length 2 or 3')
end

