Home > matGeom > geom2d > edgeLength.m

edgeLength

PURPOSE ^

EDGELENGTH Return length of an edge.

SYNOPSIS ^

function len = edgeLength(varargin)

DESCRIPTION ^

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

   ---------

   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 19/02/2004

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 %
0017 %   author : David Legland
0018 %   INRA - TPV URPOI - BIA IMASTE
0019 %   created the 19/02/2004
0020 %
0021 
0022 %   HISTORY
0023 %   15/04/2005 changes definition for edge, uses [x1 y1 x2 y2] instead of
0024 %       [x0 y0 dx dy].
0025 
0026 if nargin == 1
0027     % input is an edge [X1 Y1 X2 Y2]
0028     edge = varargin{1};
0029     len = hypot(edge(:,3)-edge(:,1), edge(:,4)-edge(:,2));
0030     
0031 elseif nargin == 2
0032     % input are two points [X1 Y1] and [X2 Y2]
0033     p1 = varargin{1};
0034     p2 = varargin{2};
0035     len = hypot(p2(:,1)-p1(:,1), p2(:,2)-p1(:,2));
0036     
0037 end

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