function [Y] = ellipse_residual (X, z, a, b, alpha);
%ELLIPSE_RESIDUAL       Computes the residual vector "X - ellipse"
%
% [Y] = ellipse_residual (X, z, a, b, alpha);
% computes the residual vector "X - ellipse" in the
% transformed system (rotated by -alpha).
%
% X: given points <X(i,1), X(i,2)>
% z, a, b, alpha: ellipse parameters
%
% Y: residual vector "X - ellipse" for the transformed system.
%    <Y(i), Y(i+m)> difference vector for i-th point (m == nofpoints)
  
  s = sin(alpha);
  c = cos(alpha);
  Q = [c -s; s c];
  
  x = [X(:,1) - z(1), X(:,2) - z(2)]*Q;
  phi = ellipse_phi (x, a, b);
  Y = x - [a*cos(phi), b*sin(phi)];
  Y = [Y(:,1); Y(:,2)];

end % ellipse_residual
