EDGELENGTH Return length of an edge. L = edgeLength(EDGE); Returns the length of an edge, with parametric representation: [x1 y1 x2 y2]. The function also works for several edges, in this case input is a N-by-4 array, containing parametric representation of each edge, and output is a N-by-1 array containing length of each edge. See also edges2d, edgeAngle
0001 function len = edgeLength(varargin) 0002 %EDGELENGTH Return length of an edge. 0003 % 0004 % L = edgeLength(EDGE); 0005 % Returns the length of an edge, with parametric representation: 0006 % [x1 y1 x2 y2]. 0007 % 0008 % The function also works for several edges, in this case input is a 0009 % N-by-4 array, containing parametric representation of each edge, and 0010 % output is a N-by-1 array containing length of each edge. 0011 % 0012 % See also 0013 % edges2d, edgeAngle 0014 0015 % ------ 0016 % Author: David Legland 0017 % E-mail: david.legland@inrae.fr 0018 % Created: 2004-02-19 0019 % Copyright 2004-2024 INRA - TPV URPOI - BIA IMASTE 0020 0021 if nargin == 1 0022 % input is an edge [X1 Y1 X2 Y2] 0023 edge = varargin{1}; 0024 len = hypot(edge(:,3)-edge(:,1), edge(:,4)-edge(:,2)); 0025 0026 elseif nargin == 2 0027 % input are two points [X1 Y1] and [X2 Y2] 0028 p1 = varargin{1}; 0029 p2 = varargin{2}; 0030 len = hypot(p2(:,1)-p1(:,1), p2(:,2)-p1(:,2)); 0031 0032 end