"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/macros/arclength.sci" (22 Feb 2012, 735 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scilab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 function  s = arclength(crv, circular)
    2 // 
    3 // Computes the arclength parameter of a curve
    4 //
    5 // 
    6 // Input: 
    7 //   - nx2 curve vector [x y]
    8 // Output: 
    9 //   - arc length at each point, with s[1] = 0;
   10 //
   11 // AUTHOR
   12 //    Ricardo Fabbri  <rfabbri@(not this part) gmail d0t com>
   13 //    Cybernetic Vision Research Group
   14 //    Luciano da Fontoura Costa, supervisor.
   15 //    http://siptoolbox.sf.net
   16 //
   17 // $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $
   18 
   19 n = size(crv,1);
   20 s = zeros(n,1);
   21 
   22 idx = 2:n;
   23 dx = crv(idx,1) - crv(idx-1,1);
   24 dy = crv(idx,2) - crv(idx-1,2);
   25 s(idx) = sqrt(dx.*dx + dy.*dy);
   26 
   27 for i=idx
   28   s(i) = s(i-1) + s(i);
   29 end
   30 
   31 
   32 [%nargout,%nargin] = argn(0)
   33 
   34 if %nargin == 2
   35   s(n+1)  = s(n) + norm([crv(n,:) - crv(1,:)]);
   36 end
   37 
   38 endfunction