MEDIANLINE Create a median line between two points. L = medianLine(P1, P2); Create the median line of points P1 and P2, that is the line containing all points located at equal distance of P1 and P2. L = medianLine(PTS); Creates the median line of 2 points, given as a 2*2 array. Array has the form: [ [ x1 y1 ] ; [ x2 y2 ] ] L = medianLine(EDGE); Creates the median of the edge. Edge is a 1*4 array, containing [X1 Y1] coordinates of first point, and [X2 Y2], the coordinates of the second point. Example % Draw the median line of two points P1 = [10 20]; P2 = [30 50]; med = medianLine(P1, P2); figure; axis square; axis([0 100 0 100]); drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); drawLine(med) % Draw the median line of an edge P1 = [50 60]; P2 = [80 30]; edge = createEdge(P1, P2); figure; axis square; axis([0 100 0 100]); drawEdge(edge, 'linewidth', 2) med = medianLine(edge); drawLine(med) See also lines2d, createLine, orthogonalLine
0001 function line = medianLine(varargin) 0002 %MEDIANLINE Create a median line between two points. 0003 % 0004 % L = medianLine(P1, P2); 0005 % Create the median line of points P1 and P2, that is the line containing 0006 % all points located at equal distance of P1 and P2. 0007 % 0008 % L = medianLine(PTS); 0009 % Creates the median line of 2 points, given as a 2*2 array. Array has 0010 % the form: 0011 % [ [ x1 y1 ] ; [ x2 y2 ] ] 0012 % 0013 % L = medianLine(EDGE); 0014 % Creates the median of the edge. Edge is a 1*4 array, containing [X1 Y1] 0015 % coordinates of first point, and [X2 Y2], the coordinates of the second 0016 % point. 0017 % 0018 % Example 0019 % % Draw the median line of two points 0020 % P1 = [10 20]; 0021 % P2 = [30 50]; 0022 % med = medianLine(P1, P2); 0023 % figure; axis square; axis([0 100 0 100]); 0024 % drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); 0025 % drawLine(med) 0026 % 0027 % % Draw the median line of an edge 0028 % P1 = [50 60]; 0029 % P2 = [80 30]; 0030 % edge = createEdge(P1, P2); 0031 % figure; axis square; axis([0 100 0 100]); 0032 % drawEdge(edge, 'linewidth', 2) 0033 % med = medianLine(edge); 0034 % drawLine(med) 0035 % 0036 % 0037 % See also 0038 % lines2d, createLine, orthogonalLine 0039 0040 % ------ 0041 % Author: David Legland 0042 % E-mail: david.legland@inrae.fr 0043 % Created: 2003-10-31 0044 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE 0045 0046 nargs = length(varargin); 0047 0048 if nargs == 1 0049 tab = varargin{1}; 0050 if size(tab, 2)==2 0051 % input is an array of two points 0052 x0 = tab(1,1); 0053 y0 = tab(1,2); 0054 dx = tab(2,1)-x0; 0055 dy = tab(2,2)-y0; 0056 else 0057 % input is an edge 0058 x0 = tab(:, 1); 0059 y0 = tab(:, 2); 0060 dx = tab(:, 3) - tab(:, 1); 0061 dy = tab(:, 4) - tab(:, 2); 0062 end 0063 0064 elseif nargs==2 0065 % input is given as two points, or two point arrays 0066 p1 = varargin{1}; 0067 p2 = varargin{2}; 0068 x0 = p1(:, 1); 0069 y0 = p1(:, 2); 0070 dx = bsxfun(@minus, p2(:, 1), x0); 0071 dy = bsxfun(@minus, p2(:, 2), y0); 0072 0073 else 0074 error('Too many input arguments'); 0075 end 0076 0077 % compute median using middle point of the edge, and the direction vector 0078 % rotated by 90 degrees counter-clockwise 0079 line = [bsxfun(@plus, x0, dx/2), bsxfun(@plus, y0, dy/2), -dy, dx];