uses crt, dos, graph;
const
  x01=100;
  x03=23.5;
  x12=98.4;
  x23=26.24;
  x34=100;
  x24=97;
  x45=350;
  x56=224;
  x36=273;
  var tau,phi,x13,delta,beta,gamma,x46,lamda,beta1,beta2,alpha1,alpha2,lamda1,lamda2: real;
  var gd,gm,i: integer;
  var dx,dy:real;

function acos(x: real):real;
var ac: real;
begin
    if (x>0) then ac:=arctan((sqrt(1-x*x))/x);
    if (x=0) then ac:=pi/2;
    if (x<0) then ac:=arctan((sqrt(1-x*x))/x)+pi;
    acos:=ac;
end;

function asin(x:real):real;
begin
  asin:=arctan(x/sqrt(1-x*x))
end;

function sgn(x: real):real;
  var c:real;
begin
  if x>=0 then c:=1 else c:=-1;
  sgn:=c;
  end;
begin
  gd:=detect;
  initgraph(gd,gm,'C:\modellierungswoche\gruppe3\');
  dx:=x03+x36+x01+50;
  dy:=200;
  setlinestyle(1,1,2);
  repeat
  for i:=1 to 360 do begin
   phi:=pi*(i)/180;
   x13:=sqrt(x01*x01+x03*x03-2*x01*x03*cos(phi));
   if ((x01<x03) and (x01<x23) and (x01<x12)) then begin
     delta:=acos((x23*x23+x34*x34-x24*x24)/(2*x23*x34));
     beta1:=acos((x13*x13+x03*x03-x01*x01)/(2*x13*x03));
     beta2:=acos((x23*x23+x13*x13-x12*x12)/(2*x23*x13));
     beta:=beta1+beta2;
   gamma:=pi-beta-delta;
   x46:=sqrt(x36*x36+x34*x34-2*x36*x34*cos(gamma));
   lamda:=(acos((x36*x36+x46*x46-x34*x34)/(2*x36*x46))+acos((x56*x56+x46*x46-x45*x45)/(2*x56*x46)));
   tau:=pi-lamda;
   end else begin
     alpha1:=acos((x13*x13+x12*x12-x23*x23)/(2*x13*x12));
     alpha2:=asin(x03*sin(PHI)/x13);
     beta1:=pi-alpha2-phi;
     beta2:=acos((x23*x23+x13*x13-x12*x12)/(2*x23*x13));
     beta:=beta1-beta2;
     delta:=acos((x23*x23+x34*x34-x24*x24)/(2*x23*x34));
     gamma:=pi-delta-beta;
     x46:=sqrt(x36*x36+x34*x34-2*x36*x34*cos(gamma));
     lamda1:=(acos((x36*x36+x46*x46-x34*x34)/(2*x36*x46)));
     lamda2:=(acos((x56*x56+x46*x46-x45*x45)/(2*x56*x46)));
     if (((0<gamma) and (gamma<pi)) or (gamma>2*pi)) then lamda:=lamda1+lamda2 else lamda:=-lamda1+lamda2;
     tau:=pi-lamda;
   end;
   setcolor(white);
   line(trunc(x01),getmaxy-trunc(dy),trunc(x01*cos(phi)+x01),getmaxy-trunc(x01*sin(phi)+dy));
   line(trunc(x01*cos(phi)+x01),getmaxy-trunc(x01*sin(phi)+dy),trunc(x03-x23*cos(beta)+x01),getmaxy-trunc(x23*sin(beta)+dy));
   line(trunc(x01),getmaxy-trunc(dy),trunc(x01+x03),getmaxy-trunc(dy));
   line(trunc(x01+x03),getmaxy-trunc(dy),trunc(x01+x03-x23*cos(beta)),getmaxy-trunc(dy+x23*sin(beta)));
   line(trunc(x01+x03),getmaxy-trunc(dy),trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(GAMMA)));
   line(trunc(x01+x03-x23*cos(beta)),getmaxy-trunc(dy+x23*sin(beta)),
     trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(GAMMA)));
   line(trunc(x01+x03+x36),getmaxy-trunc(dy),trunc(x01+x03),getmaxy-trunc(dy));
   line(trunc(x01+x03+x36),getmaxy-trunc(dy),trunc(x01+x56*cos(tau)+x03+x36),getmaxy-trunc(dy+x56*sin(tau)));
   line(trunc(x01+x56*cos(tau)+x03+x36),getmaxy-trunc(dy+x56*sin(tau)),
    trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(gamma)));
   setcolor(black) ;
   delay(20);
   line(trunc(x01),getmaxy-trunc(dy),trunc(x01*cos(phi)+x01),getmaxy-trunc(x01*sin(phi)+dy));
   line(trunc(x01*cos(phi)+x01),getmaxy-trunc(x01*sin(phi)+dy),trunc(x03-x23*cos(beta)+x01),getmaxy-trunc(x23*sin(beta)+dy));
   line(trunc(x01),getmaxy-trunc(dy),trunc(x01+x03),getmaxy-trunc(dy));
   line(trunc(x01+x03),getmaxy-trunc(dy),trunc(x01+x03-x23*cos(beta)),getmaxy-trunc(dy+x23*sin(beta)));
   line(trunc(x01+x03),getmaxy-trunc(dy),trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(GAMMA)));
   line(trunc(x01+x03-x23*cos(beta)),getmaxy-trunc(dy+x23*sin(beta)),
     trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(GAMMA)));
   line(trunc(x01+x03+x36),getmaxy-trunc(dy),trunc(x01+x03),getmaxy-trunc(dy));
   line(trunc(x01+x03+x36),getmaxy-trunc(dy),trunc(x01+x56*cos(tau)+x03+x36),getmaxy-trunc(dy+x56*sin(tau)));
   line(trunc(x01+x56*cos(tau)+x03+x36),getmaxy-trunc(dy+x56*sin(tau)),
    trunc(x01+x03+x34*cos(gamma)),getmaxy-trunc(dy+x34*sin(gamma)));
    if keypressed then exit;
  end;
  until keypressed;
end.