Home > matGeom > geom2d > drawShape.m

drawShape

PURPOSE ^

DRAWSHAPE Draw various types of shapes (circles, polygons...).

SYNOPSIS ^

function varargout = drawShape(type, param, varargin)

DESCRIPTION ^

DRAWSHAPE Draw various types of shapes (circles, polygons...).

   drawShape(TYPE, PARAM)
   Draw the shape of type TYPE, specified by given parameter PARAM. TYPE
   can be one of {'circle', 'ellipse', 'rect', 'polygon', 'curve'}
   PARAM depend on the type. For example, if TYPE is 'circle', PARAM will
   contain [x0 y0 R].

   Examples :
   drawShape('circle', [20 10 30]);
   Draw circle centered on [20 10] with radius 10.
   drawShape('rect', [20 20 40 10 pi/3]);
   Draw rectangle centered on [20 20] with length 40 and width 10, and
   oriented pi/3 wrt axis Ox.
   

   drawShape(..., OPTION)
   also specifies drawing options. OPTION can be 'draw' (default) or
   'fill'.

   ---------

   author : David Legland 
   INRA - TPV URPOI - BIA IMASTE
   created the 07/04/2005.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawShape(type, param, varargin)
0002 %DRAWSHAPE Draw various types of shapes (circles, polygons...).
0003 %
0004 %   drawShape(TYPE, PARAM)
0005 %   Draw the shape of type TYPE, specified by given parameter PARAM. TYPE
0006 %   can be one of {'circle', 'ellipse', 'rect', 'polygon', 'curve'}
0007 %   PARAM depend on the type. For example, if TYPE is 'circle', PARAM will
0008 %   contain [x0 y0 R].
0009 %
0010 %   Examples :
0011 %   drawShape('circle', [20 10 30]);
0012 %   Draw circle centered on [20 10] with radius 10.
0013 %   drawShape('rect', [20 20 40 10 pi/3]);
0014 %   Draw rectangle centered on [20 20] with length 40 and width 10, and
0015 %   oriented pi/3 wrt axis Ox.
0016 %
0017 %
0018 %   drawShape(..., OPTION)
0019 %   also specifies drawing options. OPTION can be 'draw' (default) or
0020 %   'fill'.
0021 %
0022 %   ---------
0023 %
0024 %   author : David Legland
0025 %   INRA - TPV URPOI - BIA IMASTE
0026 %   created the 07/04/2005.
0027 %
0028 
0029 %   HISTORY
0030 
0031 if ~iscell(type)
0032     type = {type};
0033 end
0034 if ~iscell(param)
0035     tmp = cell(1, size(param, 1));
0036     for i=1:size(param, 1)
0037         tmp{i} = param(i,:);
0038     end
0039     param = tmp;
0040 end
0041 
0042 % compute drawing options
0043 option = 'draw';
0044 if ~isempty(varargin)
0045     var = varargin{1};
0046     if strcmpi(var, 'fill')
0047         option = 'fill';
0048     end
0049 end
0050 
0051     
0052 % transform each shape into a polygon
0053 shape = cell(1,length(type));
0054 for i = 1:length(type)    
0055     if strcmpi(type{i}, 'circle')
0056         shape{i} = circleToPolygon(param{i}, 128);
0057     elseif strcmpi(type{i}, 'rect')
0058         shape{i} = rectToPolygon(param{i});
0059     elseif strcmpi(type{i}, 'polygon')
0060         shape{i} = param{i};        
0061     end
0062 end
0063 
0064 
0065 % draw or fill each shape as polygon
0066 hold on;
0067 h = zeros(length(shape), 1);
0068 if strcmp(option, 'draw')
0069     for i = 1:length(shape)
0070         h(i) = drawPolygon(shape{i});
0071     end
0072 else
0073     for i = 1:length(shape)
0074         h(i) = fillPolygon(shape{i});
0075     end
0076 end
0077 
0078 % foramt output
0079 if nargout > 0
0080     varargout = {h};
0081 end

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