function Fc = computeFc ( n, Polygon )
// function Fc = computeFc ( n, Polygon )
//
// calculation of Fourier-coefficients of closed polygons in the 
// complex plane 
//
// input:    n            maximum index of coefficients, integer >=1
//
//           Polygon      vector of complex values representing the 
//                        polygon. 
//
// output:   Fc           vector of (complex valued) Fourier-coefficients
//                        c_i, i ranging from -n,...,0,..., +n

// Bernard Haasdonk 14.11.2001

[out,in] = argn(0);

if in~=2, 
   error('wrong number of input arguments.');
end;

// normalized differences of polygon vertices
X = Polygon;
X_d = [ X(2:length(X)) ; X(1) ] - X;
X_d_abs = abs( X_d );
Z_d = X_d ./ X_d_abs;
Z_dd =  Z_d - [ Z_d(length(Z_d)) ; Z_d(1:(length(Z_d)-1)) ];

//curve length as parameter
T = cumsum(X_d_abs);
periode = T(length(T));
T = [0 ; T(1:(length(T)-1))];

// base functions
N = [-n:-1 1:n]';
B = exp( (-%i*2*%pi/periode ).*( N * T') );

// Fourier coefficients
Fc = B * Z_dd;
Fc = - Fc .* periode ./ (2*%pi)^2 ./ N.^2;

// Fourier coefficient c0
c0 = ( [ X(2:length(X)) ; X(1) ] + X ).' * X_d_abs;
c0 = c0 / 2 / periode;

Fc = [ Fc(1:n); c0; Fc(n+1:2*n) ];

endfunction;






