function [z, a, b, alpha] = bookstein_svd (X, show);
%BOOKSTEIN_SVD  Algebraic ellipse fit
%
% [z, a, b, alpha] = bookstein_svd (X, show{0});
%
% Approximate ellipse to points <X(i,1),X(i,2)>.
% Invariant under euclidian transformation, see
% BOOKSTEIN, "Fitting conic secions to scattered data", in
% Computer graphics & image processing 9, 56-71 (1979).
% unlike BOOKSTEIN, SVD is used for solution.
%
% X: given points <X(i,1),X(i,2)>
% show: if (show == 1), test output
%
% z, a, b, alpha: parameters for ellipse found

  if (nargin < 2), show = 0; end;

  m      = size(X,1);
  AA     = [ X(:,1) X(:,2) ones(size(X(:,1))) ...
             X(:,1).^2  sqrt(2)*X(:,1).*X(:,2) X(:,2).^2];
     
  [d, a] = clsq (AA, 3);
  u = [a(1); sqrt(2)*a(2); a(3); d];

  [z, a, b, alpha, err] = ellipse_params (u, show);
  
end % bookstein_svd
