%EPIZYKLODEMO  animierte grafische Demo zur Definition von Epizykloiden
% Durch Vor-Definieren der globalen Variablen ZYKRADFAC
% (kleiner oder =  1, Radiusverhaeltnis, negativ Hypozykloide)
% kann der Typ der Epizykloiden gew{\"a}hlt werden (Defaultwert = 1/2). 
%   Copyright 2003 HSZ-T, Zuerich , Dr. Stefan Adam
t = 2*pi*(0:0.01:1.4) ;  w = 2*pi*(0:0.01:1);
clf ;  hold on
if  exist('ZYKRADFAC') == 0
  ZYKRADFAC = 0.5
end 
R=6 ;  Ra=ZYKRADFAC*R;
frc = 1+ R/Ra ; fr = R/Ra;
polx = 0 ; poly = R;
xkri = R*cos(w) ;  ykri = R*sin(w);
plot(xkri,ykri,'k');  axis([-20 20 -20 20]); axis square
Mofram=moviein(length(t));
for k=1:length(t)
  x=(R+Ra)*sin(t(k)) + Ra*cos(w);  y=(R+Ra)*cos(t(k)) + Ra*sin(w);
  lx = 0:0.005*2*pi:t(k);
  bix = (R)*sin(lx);  biy = (R)*cos(lx);
  bx=(R+Ra)*sin(t(k)) - Ra*sin(t(k)+fr*lx);
  by=(R+Ra)*cos(t(k)) - Ra*cos(t(k)+fr*lx);
  vx = [(R+Ra)*sin(t(k)) (R+Ra)*sin(t(k))-Ra*sin(frc*t(k))];
  vy = [(R+Ra)*cos(t(k))  (R+Ra)*cos(t(k))-Ra*cos(frc*t(k))];
  pnewx = (R+Ra)*sin(t(k)) - Ra*sin(frc*t(k));
  pnewy = (R+Ra)*cos(t(k)) - Ra*cos(frc*t(k));
  if k > 1 
    delete(circ); delete(cent);  delete(arc);
    delete(vec);  delete(pt);
  end
  circ = plot(x,y,'k');
  cent = plot( (R+Ra)*sin(t(k)), (R+Ra)*cos(t(k)) ,'k.');
  arc  = plot(bx,by,'g');   vec = plot(vx,vy,'b');
  pt = plot(pnewx,pnewy,'m.');
  plot([polx pnewx],[poly pnewy],'r');
  polx = pnewx;  poly = pnewy;
  plot(bix, biy,'g');
  Mofram(:,k)=getframe;  pause(0.1)
end 
pause(0.8);  movie(Mofram,-3); movie(Mofram,1);
