% calculate center of line mass

% x,y are coordinates

x=x(:);
y=y(:);

nseg = size(x,1)-1;
if nseg+1 ~= size(y,1), error ('lengths must be the same'); end;

sx=0; sx2=0; sy=0; sy2=0;
for k = 1:nseg
  dx = x(k+1) - x(k);
  dy = y(k+1) - y(k);
  ds = sqrt(dx^2+dy^2);
  sx2 = sx2 + x(k+1) * ds;
  sx = sx + ds;
  sy2 = sy2 + y(k+1) * ds;
  sy = sy + ds;
end;

mx = sx2/sx;
my = sy2/sy;
