% Demo4

% Lets see what happens when both the initial x and the initial y
% are in span{cVec,sVec}


  n = 20;
  nSmoothings = 1;
  [c,s] = csVecs(n);

  for degx = 0:30:180
     for degy = 0:30:180
%       Generate the initial x and y...
        thetax = degx*(pi/180);
        thetay = degy*(pi/180);
        x =  cos(thetax)*c + sin(thetax)*s; x = x/norm(x);
        y = -sin(thetay)*c + cos(thetay)*s; y = y/norm(y);
%       Smooth the polygon and estimate the major and minor semiaxess...
        [xf,yf] = ShowPBetter(x,y,nSmoothings,0); 
        semiMajor = max(sqrt(xf.^2 + yf.^2));
        semiMinor = min(sqrt(xf.^2 + yf.^2));
        text(-.7,-.6,...
         sprintf('degx = %3d  degy = %3d',degx,degy))
        text(-.7,-.7,...
         sprintf('semiMajor  = %5.3f  semiMinor   = %5.3f',semiMajor,semiMinor))
%       Display possible fitting ellipses
        u = semiMajor*cos(linspace(0,2*pi));
        v = semiMinor*sin(linspace(0,2*pi));
        
        hold on
%       Rotate canonical ellipse + 45degrees
        plot((u-v)/sqrt(2),(u+v)/sqrt(2),'g')
%       Rotate canonical ellispe  -45 degrees
        plot((u+v)/sqrt(2),(-u+v)/sqrt(2),'c')
        hold off
        shg
        pause
     end
  end