
Program Barreau;

{
     Ecole Polytechnique  ...........................   95.403

Un triangle ABC de dimensions invariantes se d‚place dans un plan Euclidien
de telle sorte que le sommet A appartient … la droite portant l'axe Ox et
le sommet B … la droite portant l'axe Oy d'un repŠre Oxy
(l'angle alpha form‚ par les axes Ox et Oy est quelconque).

On suppose que la longueur du c“t‚ AB est ‚gale … l'unit‚ (AB=1).

                           [Figure]


1/ Ecrire un programme Turbo Pascal qui trace le contour de l'aire balay‚e
par le segment AB lors de son d‚placement.

Quelle est la mesure de cette aire ? 

Tracer la courbe montrant comment cette mesure varie en fonction de alpha.


2/ Quelle est la figure g‚om‚trique F d‚crite par le point C lors du
d‚placement du triangle ?
D‚terminer les positions de C correspondant … des extrema de la distance OC
et en d‚duire la mesure de l'aire int‚rieure … F.


3/ Tracer l'enveloppe de la droite AC.
(cette enveloppe est la courbe … laquelle la droite AC reste constamment
tangente lors de son d‚placement). 

Quelles sont les propri‚t‚s de cette enveloppe
(sym‚tries, cas particuliers, ... ) ? 

Ecrire un programme qui calcule la mesure S de l'aire int‚rieure … cette
courbe enveloppe. 

Quelle est sa plage de variation de S pour une valeur donn‚e de alpha ?


:--------------------------------------------------------------:
:    Imprimer tous les r‚sultats                               :
:     en indiquant chaque fois … quoi ils correspondent        :
:--------------------------------------------------------------:
                            -=-=-=-
 }


uses
    crt,modubase;

const
    maxn=5;
var
   n:integer;
   Car         : Char ;
   Question    : Char;

type
    Myreal=real;
    Angle=MyReal;
    points=record
       n:string[4];
       x,y:Myreal;
       end;
    vecteurs=record
       x,y:Myreal;
    end;

var
   PA,PB,PC,PM:Points;

procedure NewPoint(VAR P:points;x,y:MyReal);
begin
     P.x:=x;
     P.y:=y;
end;


function distance(A,B:points):MyReal;
var
   d:MyReal;
   i:integer;
begin
         distance:=sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));
end;

function tan(theta:Angle):MyReal;
begin
     if cos(theta)=0 then
        tan:=0
     else
     tan:=sin(theta)/cos(theta);
end;

function vectoriel(v1,v2:vecteurs):real;
begin
     vectoriel:=v1.x*v2.y-v1.y*v2.x;
end;

procedure vectorise(A,B:points;var V:vecteurs);
begin
     V.x:=B.x-A.x;
     V.y:=B.y-A.y;

end;

Function AireT(A,B,C:Points):MyReal;
var
   u,v:Vecteurs;
begin
    Vectorise(A,B,u);
    Vectorise(A,C,v);
    AireT:=0.5*vectoriel(u,v);
end;

procedure Enveloppe(A,B,A1,B1:points;var E:points);
{ E est l'intersection de AB et A1B1 }
{ on cherche u tel que AE=uAB

 et vect (A1E,A1B1)=0
   vect (uAB-AA1,A1B1)=0

   donc u = vect(AA1,A1B1)/vect (AB,A1B1)  }
var
   AA1,A1B1,AB:vecteurs;
   u,u1,u2:real;
begin
     Vectorise(A,A1,AA1);
     Vectorise(A1,B1,A1B1);
     Vectorise(A,B,AB);
     u1:=vectoriel(AA1,A1B1);
     u2:=vectoriel(AB,A1B1);
     if u2<>0 then
       begin
            u:=u1/u2;
            E.x:=B.x*u+A.x*(1-u);
            E.y:=B.y*u+A.y*(1-u);
        end;

end;

procedure TraceSegment(A,B:points);
begin
     Deplace(A.x,A.y);
     Trace(B.x,B.y);
end;



procedure Presentation;
begin;
      Efface;
      WriteLN(' ====== EP96.403 barreau mobile  =====');
      WriteLN('                                  ');
      WriteLN('                                                  ');
      WriteLN(' (1)  Cas de droites perpendiculaires     ');
      WriteLN(' (2)  Cas de droites obliques (angle alpha)   ');
      WriteLN(' (3)  Triangle ABC mobile  ');
      WriteLN(' (4)  Triangle ABC mobile  repere oblique ');
      WriteLN('                              ');
      Write('   Tapez votre Choix  :  ');
end;


procedure Question1;
var
   A,B:Points;
   Theta:Angle;
   procedure TraceTheta(theta:Angle);
   begin
        NewPoint(A,cos(theta),0);
        NewPoint(B,0,sin(theta));
        TraceSegment(A,B);
   end;

begin
     Efface;
     Writeln('+---------------------- Question nø1 -------------------------------+');
     Writeln('Ý      Cas de droites perpendiculaires                              Ý');
     Writeln('Ý                                                                   Ý');
     Writeln('+-------------------------------------------------------------------+');


     ModeGraphique;
     IsoFenetre(-1.5,1.5,-1);

     repeat
           Efface;
           Couleur(Vert);
           X_axe(0,0,1);
           Y_axe(0,0,1);
           Couleur(Brillant);
           Theta:=2*pi;
           repeat
                 TraceTheta(Theta);
                 theta:=theta-0.1;
           until theta<0;
           Pause;
     until false;

end;

procedure Question2;
var
   Xmin,Xmax,Ymin:MyReal;
   A,B:Points;
   Alpha, Theta:Angle;
   procedure TraceTheta(theta:Angle);
   var
      u:Myreal;
   begin
        A.y:=sin(theta);
        A.x:=A.y/tan(alpha);
        B.x:=A.x+cos(theta);
        B.y:=0;
   end;

begin
     Efface;
     Writeln('+---------------------- Question nø2 -------------------------------+');
     Writeln('Ý      Cas de droites formant un angle alpha                              Ý');
     Writeln('Ý                                                                   Ý');
     Writeln('+-------------------------------------------------------------------+');


     ModeGraphique;
     Xmin:=-4;Xmax:=4;Ymin:=-3;
     IsoFenetre(Xmin,Xmax,Ymin);
     alpha:=random;
           Efface;
           Couleur(Vert);
           X_axe(0,0,1);
           Deplace(ymin/tan(alpha),ymin);
           Trace(-ymin/tan(alpha),-ymin);
           Pause;
           Couleur(Brillant);
           Theta:=2*pi;
           repeat
                 TraceTheta(Theta);
                 Couleur(-brillant);
                 TraceSegment(A,B);
                 Delay(1000);
                 TraceSegment(A,B);
                 theta:=theta-0.1;
           until theta<0;
           Pause;

end;

procedure Question3;
var
   O,A,B,B1,C,C1,E,E1:Points;
   h1,h2:real;
   d1,d2,d:real;
   Theta:Angle;
const
     PasTheta=0.01;

   procedure CalculeC(theta:Angle);
   begin
        NewPoint(A,cos(theta),0);
        NewPoint(B,0,sin(theta));
        NewPoint(C,A.x+h1*B.y-h2*A.x,h1*A.x+h2*B.y);
   end;

begin
     Efface;
     Writeln('+---------------------- Question nø3 -------------------------------+');
     Writeln('Ý      Cas de droites perpendiculaires                              Ý');
     Writeln('Ý                                                                   Ý');
     Writeln('+-------------------------------------------------------------------+');


     ModeGraphique;
     IsoFenetre(-1.5,1.5,-1);
     NewPoint(O,0,0);
     repeat
           h1:=2*random-1;
           h2:=2*random-1;
           Efface;
           Couleur(Jaune);
           X_axe(0,0,1);
           Y_axe(0,0,1);
           Couleur(Brillant);
           Theta:=2*pi;
           CalculeC(Theta);
           repeat
                 d2:=d1;
                 d1:=d;
                 d:=distance(O,C);
                 Couleur(-Brillant);
                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
                 Delay(50);

                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
                 B1:=B;
                 C1:=C;
                 CalculeC(Theta);
                 Couleur(Brillant);
                 E1:=E;
                 Enveloppe(B,C,B1,C1,E);
                 Couleur(Vert);
                 TraceSegment(C,C1);
                 Couleur(Rouge);
                 if Theta<2*pi-2*PasTheta then
                    TRaceSegment(E,E1);
                 theta:=theta-PasTheta;
           until theta<0;
           Couleur(Brillant);
                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
           Pause;
     until false;

end;
procedure Question4;
var
   Aire:Myreal;
   Xmin,Xmax,Ymin:MyReal;
   O,A,B,B1,C,C1,E,E1:Points;
   h1,h2:real;
   d1,d2,d:real;
   Alpha,
   Theta:Angle;
const
     PasTheta=0.01;
   procedure CalculeC(theta:Angle);
   begin
        A.y:=sin(theta);
        A.x:=A.y*cos(alpha)/sin(alpha);
        B.x:=A.x+cos(theta);
        B.y:=0;

        NewPoint(C,A.x+h1*(B.x-A.x)+h2*(A.y-B.y),
                   A.y+h1*(B.y-A.y)+h2*(B.x-A.x));
   end;
   
begin
     Efface;
     Writeln('+---------------------- Question nø4 -------------------------------+');
     Writeln('Ý      RepŠre oblique d''angle alpha                                 Ý');
     Writeln('Ý                                                                   Ý');
     Writeln('+-------------------------------------------------------------------+');


     ModeGraphique;
     NewPoint(O,0,0);
     Xmin:=-4;Xmax:=4;Ymin:=-3;
     IsoFenetre(Xmin,Xmax,Ymin);
           alpha:=2*random;
           h1:=cos(alpha);
           h2:=sin(alpha);
      repeat
           Aire:=0;
           Efface;
           Couleur(Bleu);
           Deplace(0,0);
           Trace(0,1);
           Trace(1,1);
           Trace(1,0);
           Trace(0,0);
           Couleur(Jaune);
           X_axe(0,0,1);
           Deplace(ymin*cos(alpha)/sin(alpha),ymin);
           Trace(-ymin*cos(alpha)/sin(alpha),-ymin);
           Couleur(Brillant);
           Theta:=2*pi;
           CalculeC(Theta);
           repeat
                 d2:=d1;
                 d1:=d;
                 d:=distance(O,C);
                 Couleur(-Brillant);
                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
                 Delay(1);
                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
                 B1:=B;
                 C1:=C;
                 CalculeC(Theta);
                 Couleur(Vert);
                 TRaceSegment(C,C1);
                 E1:=E;
                 Enveloppe(B,C,B1,C1,E);
                 Couleur(Rouge);
                 if theta<2*pi-2*PasTheta then
                  begin
                     TraceSegment(E,E1);
                     Aire:=Aire+AireT(O,E,E1);
                  end;
                  theta:=theta-PasTheta;
           until theta<0;
           Couleur(Brillant);
                         TraceSegment(A,B);
                         TraceSegment(B,C);
                         TraceSegment(C,A);
           Deplace(xmin,xmax*0.6);

           Ecris('Angle alpha=');ecrisReel(alpha);
           Ecris('  Aire de l''enveloppe E=');ecrisReel(Abs(Aire));
           Pause;
           h1:=2*random-1;
           h2:=2*random-1;

      until false;


end;


begin
  Initgraphique;
  Randomize;
  while true do
  begin
     Modetexte;
     Presentation;
     write('Question choisie ? ');
     readln(question);
     case question of
          '1':  Question1;
          '2':  Question2;
          '3' : Question3;
          '4' : Question4;
     end;
     Pause;
  end;
end.
