DRAWCENTEREDEDGE Draw an edge centered on a point. Draws a centered edge, defined by a center, a length and an orientation (in degrees). This function can be used to draw principal axes of an ellipse or of an oriented box. drawCenteredEdge(EDGE) Draws an edge centered on a point. EDGE has format [XC YC L THETA], with (Xc, YC) being edge center, L being the edge length, and THETA beigng the edge orientation, in degrees (counted Counter-clockwise from horizontal). Input argument can also be a N-by-4 array, in that can several edges are drawn. drawCenteredEdge(CENTER, L, THETA) Specifies argument in seperate inputs. drawCenteredEdge(..., NAME, VALUE) Also specifies drawing options by using one or several parameter name - value pairs (see doc of plot function for details). drawCenteredEdge(AX, ...) Specifies the axis to draw the edge on. H = drawCenteredEdge(...) Returns handle(s) to the created edges(s). Example % Draw an ellipse with its two axes figure(1); clf; center = [50 40]; r1 = 30; r2 = 10; theta = 20; elli = [center r1 r2 theta]; drawEllipse(elli, 'linewidth', 2); axis([0 100 0 100]); axis equal; hold on; edges = [center 2*r1 theta ; center 2*r2 theta+90]; drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g'); See also: edges2d, drawOrientedBox, drawEllipse, centeredEdgeToEdge, drawEdge --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 05/08/2005.
0001 function varargout = drawCenteredEdge(varargin) 0002 %DRAWCENTEREDEDGE Draw an edge centered on a point. 0003 % 0004 % Draws a centered edge, defined by a center, a length and an orientation 0005 % (in degrees). This function can be used to draw principal axes of an 0006 % ellipse or of an oriented box. 0007 % 0008 % 0009 % drawCenteredEdge(EDGE) 0010 % Draws an edge centered on a point. EDGE has format [XC YC L THETA], 0011 % with (Xc, YC) being edge center, L being the edge length, and THETA 0012 % beigng the edge orientation, in degrees (counted Counter-clockwise from 0013 % horizontal). 0014 % Input argument can also be a N-by-4 array, in that can several edges 0015 % are drawn. 0016 % 0017 % drawCenteredEdge(CENTER, L, THETA) 0018 % Specifies argument in seperate inputs. 0019 % 0020 % drawCenteredEdge(..., NAME, VALUE) 0021 % Also specifies drawing options by using one or several parameter name - 0022 % value pairs (see doc of plot function for details). 0023 % 0024 % drawCenteredEdge(AX, ...) 0025 % Specifies the axis to draw the edge on. 0026 % 0027 % H = drawCenteredEdge(...) 0028 % Returns handle(s) to the created edges(s). 0029 % 0030 % Example 0031 % % Draw an ellipse with its two axes 0032 % figure(1); clf; 0033 % center = [50 40]; 0034 % r1 = 30; r2 = 10; 0035 % theta = 20; 0036 % elli = [center r1 r2 theta]; 0037 % drawEllipse(elli, 'linewidth', 2); 0038 % axis([0 100 0 100]); axis equal; 0039 % hold on; 0040 % edges = [center 2*r1 theta ; center 2*r2 theta+90]; 0041 % drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g'); 0042 % 0043 % See also: 0044 % edges2d, drawOrientedBox, drawEllipse, centeredEdgeToEdge, drawEdge 0045 % 0046 % --------- 0047 % author : David Legland 0048 % INRA - TPV URPOI - BIA IMASTE 0049 % created the 05/08/2005. 0050 % 0051 0052 % HISTORY 0053 % 2007-06-15 update doc, clean up code 0054 % 2011-05-18 use angle in degrees, cleanup code and doc 0055 % 2011-10-11 add management of axes handle 0056 0057 0058 %% process input variables 0059 0060 if nargin < 1 0061 error('Function requires an input argument'); 0062 end 0063 0064 % extract handle of axis to draw on 0065 if isAxisHandle(varargin{1}) 0066 ax = varargin{1}; 0067 varargin(1) = []; 0068 else 0069 ax = gca; 0070 end 0071 0072 var = varargin{1}; 0073 if size(var, 2) == 4 0074 % manage edge in single parameter 0075 len = var(:, 3); 0076 theta = var(:, 4); 0077 center = var(:, 1:2); 0078 0079 N = size(center, 1); 0080 varargin(1) = []; 0081 0082 elseif length(varargin) >= 3 0083 % parameters given in different arguments 0084 0085 % size of data 0086 center = varargin{1}; 0087 len = varargin{2}; 0088 theta = varargin{3}; 0089 varargin(1:3) = []; 0090 0091 % ensure all data have same size 0092 NP = size(center, 1); 0093 NL = size(len, 1); 0094 ND = size(theta, 1); 0095 N = max([NP NL ND]); 0096 if N > 1 0097 if NP == 1, center = repmat(center, [N 1]); end 0098 if NL == 1, len = repmat(len, [N 1]); end 0099 if ND == 1, theta = repmat(theta, [N 1]); end 0100 end 0101 0102 end 0103 0104 % extract drawing options 0105 options = varargin(:); 0106 0107 0108 %% Draw edges 0109 0110 % coordinates of center point 0111 xc = center(:, 1); 0112 yc = center(:, 2); 0113 0114 % convert angle to radians 0115 theta = theta * pi / 180; 0116 0117 % computation shortcuts 0118 cot = cos(theta); 0119 sit = sin(theta); 0120 0121 % compute starting and ending points 0122 x1 = xc - len .* cot / 2; 0123 x2 = xc + len .* cot / 2; 0124 y1 = yc - len .* sit / 2; 0125 y2 = yc + len .* sit / 2; 0126 0127 0128 % draw the edges 0129 h = zeros(N, 1); 0130 for i = 1:N 0131 h(i) = plot(ax, [x1(i) x2(i)], [y1(i) y2(i)]); 0132 end 0133 0134 % apply style to edges 0135 if ~isempty(options) > 0 0136 for i = 1:N 0137 set(h(i), options{:}); 0138 end 0139 end 0140 0141 0142 %% Format output 0143 0144 % process output arguments 0145 if nargout > 0 0146 varargout = {h}; 0147 end