DRAWEDGE Draw an edge given by 2 points. drawEdge(x1, y1, x2, y2); draw an edge between the points (x1 y1) and (x2 y2). drawEdge([x1 y1 x2 y2]) ; drawEdge([x1 y1], [x2 y2]); specify data either as bundled edge, or as 2 points The function supports 3D edges: drawEdge([x1 y1 z1 x2 y2 z2]); drawEdge([x1 y1 z1], [x2 y2 z2]); drawEdge(x1, y1, z1, x2, y2, z2); Arguments can be single values or array of size [N*1]. In this case, the function draws multiple edges. H = drawEdge(..., OPT), with OPT being a set of pairwise options, can specify color, line width and so on... H = drawEdge(...) return handle(s) to created edges(s) See also: edges2d, drawCenteredEdge, drawLine
0001 function varargout = drawEdge(varargin) 0002 %DRAWEDGE Draw an edge given by 2 points. 0003 % 0004 % drawEdge(x1, y1, x2, y2); 0005 % draw an edge between the points (x1 y1) and (x2 y2). 0006 % 0007 % drawEdge([x1 y1 x2 y2]) ; 0008 % drawEdge([x1 y1], [x2 y2]); 0009 % specify data either as bundled edge, or as 2 points 0010 % 0011 % The function supports 3D edges: 0012 % drawEdge([x1 y1 z1 x2 y2 z2]); 0013 % drawEdge([x1 y1 z1], [x2 y2 z2]); 0014 % drawEdge(x1, y1, z1, x2, y2, z2); 0015 % 0016 % Arguments can be single values or array of size [N*1]. In this case, 0017 % the function draws multiple edges. 0018 % 0019 % H = drawEdge(..., OPT), with OPT being a set of pairwise options, can 0020 % specify color, line width and so on... 0021 % 0022 % H = drawEdge(...) return handle(s) to created edges(s) 0023 % 0024 % See also: 0025 % edges2d, drawCenteredEdge, drawLine 0026 % 0027 0028 % --------- 0029 % author : David Legland 0030 % INRA - TPV URPOI - BIA IMASTE 0031 % created the 31/10/2003. 0032 % 0033 0034 % HISTORY 0035 % 19/02/2004 add support for arrays of edges. 0036 % 31/03/2004 change format of edges to [P1 P2] and variants. 0037 % 28/11/2004 add support for 3D edges 0038 % 01/08/2005 add support for drawing options 0039 % 31/05/2007 update doc, and code makeup 0040 % 03/08/2010 re-organize code 0041 0042 % separate edge and optional arguments 0043 [ax, edge, options] = parseInputArguments(varargin{:}); 0044 0045 % save hold state 0046 holdState = ishold(ax); 0047 hold(ax, 'on'); 0048 0049 % draw the edges 0050 if size(edge, 2) == 4 0051 h = drawEdge_2d(ax, edge, options); 0052 else 0053 h = drawEdge_3d(ax, edge, options); 0054 end 0055 0056 % restore hold state 0057 if ~holdState 0058 hold(ax, 'off'); 0059 end 0060 0061 % eventually return handle to created edges 0062 if nargout > 0 0063 varargout = {h}; 0064 end 0065 0066 0067 function h = drawEdge_2d(ax, edge, options) 0068 0069 h = -1 * ones(size(edge, 1), 1); 0070 0071 for i = 1:size(edge, 1) 0072 if isnan(edge(i,1)) 0073 continue; 0074 end 0075 0076 h(i) = plot(ax, edge(i, [1 3]), edge(i, [2 4]), options{:}); 0077 end 0078 0079 0080 function h = drawEdge_3d(ax, edge, options) 0081 0082 h = -1 * ones(size(edge, 1), 1); 0083 0084 for i = 1:size(edge, 1) 0085 if isnan(edge(i,1)) 0086 continue; 0087 end 0088 0089 h(i) = plot3(ax, edge(i, [1 4]), edge(i, [2 5]), edge(i, [3 6]), options{:}); 0090 end 0091 0092 0093 function [ax, edge, options] = parseInputArguments(varargin) 0094 0095 % extract handle of axis to draw on 0096 if isAxisHandle(varargin{1}) 0097 ax = varargin{1}; 0098 varargin(1) = []; 0099 else 0100 ax = gca; 0101 end 0102 0103 % find the number of arguments defining edges 0104 nbVal = 0; 0105 for i = 1:length(varargin) 0106 if isnumeric(varargin{i}) 0107 nbVal = nbVal+1; 0108 else 0109 % stop at the first non-numeric value 0110 break; 0111 end 0112 end 0113 0114 % extract drawing options 0115 options = varargin(nbVal+1:end); 0116 0117 % ensure drawing options have correct format 0118 if length(options) == 1 0119 options = [{'color'}, options]; 0120 end 0121 0122 % extract edges characteristics 0123 switch nbVal 0124 case 1 0125 % all parameters in a single array 0126 edge = varargin{1}; 0127 0128 case 2 0129 % parameters are two points, or two arrays of points, of size N*2. 0130 p1 = varargin{1}; 0131 p2 = varargin{2}; 0132 edge = [p1 p2]; 0133 0134 case 4 0135 % parameters are 4 parameters of the edge : x1 y1 x2 and y2 0136 edge = [varargin{1} varargin{2} varargin{3} varargin{4}]; 0137 0138 case 6 0139 % parameters are 6 parameters of the edge : x1 y1 z1 x2 y2 and z2 0140 edge = [varargin{1} varargin{2} varargin{3} varargin{4} varargin{5} varargin{6}]; 0141 0142 otherwise 0143 error('drawEdge:WrongNumberOfParameters', 'Wrong number of parameters'); 0144 end