PROGRAM Transformation_complexe;
{
Epreuve informatique de l'Ecole Polytechnique           94.268
--------------------------------------------------------------

1°


+------------------------------------------------------------+
¦              Imprimer tous les résultats                   ¦
¦     en indiquant chaque fois à quoi ils correspondent      ¦
+------------------------------------------------------------+


     }


uses crt, modubase;

Const
     maxn=100;
     maxn2=15;
     zoom=4;
     pas=0.1;
     nv='x';    { nom de la variable  }


Type
    Points = record
              x,y:real;
             end;
    Vecteurs = record
              x,y:real;
             end;
    Complexe = record
             Partie_Reelle    : Real;
             Partie_Imaginaire : Real;
             end;
    Polaire = record
             Rho       : Real;
             Theta     : Real;
             end;
    Fonction =  array[0..maxn] of complexe;
    Fonction2 =  array[0..maxn2,0..maxn2] of complexe;



VAR
   Ch        : char;
   i         : integer;
   zA,zB     : Complexe;
   a,b,c,d   : complexe;
   casf      : byte;
   u : real;

CONST
     Zero_complexe:Complexe=(Partie_Reelle:0;Partie_Imaginaire:0);
     Un_complexe  :Complexe=(Partie_Reelle:1;Partie_Imaginaire:0);

     
Procedure Joindre(z1,z2:complexe);
begin
     with z1 do Deplace(Partie_Reelle,Partie_Imaginaire);
     with z2 do Trace  (Partie_Reelle,Partie_Imaginaire);
end ;


Function module(z:complexe):real;
begin
     With z do
          module:=sqrt(sqr(Partie_reelle)+sqr(Partie_Imaginaire));
end;

Function angle(z:complexe):real;
begin
   with z do
     if Partie_Reelle>0 then
              Angle:=ArcTan(partie_imaginaire/partie_reelle)
     else
         if Partie_Reelle<0 then
              Angle:=Atan(partie_imaginaire/partie_reelle)+pi
         else
             if Partie_Imaginaire>0 then
                Angle:=pi/2
             else
                 if Partie_Imaginaire<0 then
                    Angle:=-pi/2
                 else
                     Angle:=0;
end;

Procedure Convertit_en_polaire(z:complexe;VAR p:Polaire);
begin
     p.rho:=module(z);
     p.theta:=angle(z);
end;



Procedure Cree_Complexe(VAR z:Complexe;x,y:Real);
begin
     z.Partie_reelle    :=x;
     z.Partie_Imaginaire:=y;
end;

Procedure Conjugue(VAR z:complexe);
begin
     With z do
          Partie_Imaginaire:=-Partie_Imaginaire;
end;

Procedure Exp_Complexe(VAR z:Complexe);
begin
     With z do
          Cree_complexe(z,Exp(Partie_reelle)*cos(Partie_imaginaire),
                          Exp(Partie_reelle)*sin(Partie_imaginaire));
end;

Procedure Add_Complexe(VAR z:Complexe;x,y:Complexe);
begin
     Cree_complexe(z,x.Partie_Reelle+y.Partie_Reelle,
                     x.Partie_Imaginaire+y.Partie_Imaginaire);
end;

Procedure Sub_Complexe(VAR z:Complexe;x,y:Complexe);
begin
     Cree_complexe(z,x.Partie_Reelle-y.Partie_Reelle,
                     x.Partie_Imaginaire-y.Partie_Imaginaire);
end;

Procedure Mul_Complexe(VAR z:Complexe;x,y:Complexe);
begin
     Cree_complexe(z,x.Partie_Reelle*y.Partie_Reelle
                     -x.Partie_Imaginaire*y.Partie_Imaginaire,
                     x.Partie_Reelle*y.Partie_Imaginaire
                         +y.Partie_Reelle*x.Partie_Imaginaire);
end;
                         
Procedure Homothetie(VAR z:Complexe;lambda:real);
begin
     Cree_complexe(z,z.Partie_Reelle    *lambda,
                     z.Partie_imaginaire*lambda);
end;

Procedure Inverse(VAR z:Complexe);
begin
     Conjugue(z);
     if module(z)>0 then
        Homothetie(z,1/sqr(module(z)));
end;

Procedure Logarithme(VAR z:Complexe);
begin
     if module(z)>0 then
     Cree_complexe(z,Ln(module(z)),angle(z));
end;


Procedure Div_Complexe(VAR z:Complexe;x,y:Complexe);
begin
     Inverse(y);
     Mul_complexe(z,x,y);
end;

Procedure Transforme(VAR z:Complexe);
{                   z:=(az+b)/(cz+d) }

var
   z1,z2:complexe;
begin
     Mul_complexe(z1,a,z);
     Add_complexe(z1,z1,b);
     Mul_complexe(z2,c,z);
     Add_complexe(z2,z2,d);
     Div_complexe(z,z1,z2);
end;




Procedure segment(zA,zB : complexe);
const
     nombre=200;
var
   n:integer;
   t:real;
   z,z0,z1,z2: complexe;
begin
     z:=zA;
     for n:=0 to nombre do
         begin
              z0:=z;
              z1:=zA;
              z2:=zB;
              Homothetie(z2,n);
              Homothetie(z1,nombre-n);
              Add_complexe(z,z1,z2);
              Homothetie(z,1/nombre);
              Transforme(z0);
              z1:=z;
              Transforme(z1);
              Joindre(z0,z1);
         end;
end;









Procedure Presentation;
begin;
      ModeTexte;
      Efface;
      WriteLN(' ======= Transformation du Plan Complexe =====');
      WriteLN('                                               ');
      WriteLN('                                               ');
      WriteLN('                                               ');
      WriteLN('   (1) cas f(x) = x*x                          ');
      WriteLN('   (2)                                    ');
      WriteLN('   (3)                                         ');
      WriteLN('                                               ');
      WriteLN('   Tapez votre choix                           ');
      WriteLN('                                               ');
      WriteLN('                                               ');
end;

Procedure Question1;
Const
     Xmin=-10;
     Xmax= 10;
     Ymin=-6;
     Ymax= 6;
     Size=20;
Var
   k:integer;
   f,FFT:fonction;
begin
     Efface;
     Writeln('+---------------------- Question n°1 -------------------------------+');
     Writeln('¦                                                                   ¦');
     Writeln('¦   Transformation dans le plan complexe  Z=f(z)                    ¦');
     Writeln('¦                                                                   ¦');
     Writeln('¦    (1)  Z=Log(z)                                                  ¦');
     Writeln('¦    (2)  Z=(z+a)/(z-a)                                             ¦');
     Writeln('¦    (3)  Z= (a-b.exp(z))/(1-exp(z))                                ¦');
     Writeln('¦                                                                   ¦');
     Writeln('+-------------------------------------------------------------------+');
     ReadLn(casf);
     Randomize;
     ModeGraphique;
      IsoFenetre(xmin,xmax,ymin);
      Couleur(Blanc);
      X_Axe(0,0,1);
      Y_Axe(0,0,1);
      Couleur(Brillant);
      Deplace(xmin,-ymin);
      Ecris('Transformation du plan complexe : Z=f(z)');
      Cree_complexe(a,2,0);
      Cree_complexe(b,-2,0);

      for i:=-Size to SIze do
       begin
            u:=i/10;

                  Cree_complexe(zA,-Size,u);
                  Cree_complexe(zB,Size,u);
                  Couleur(vert);
                  Segment(zA,zB);
                  Cree_complexe(zA,u,-Size);
                  Cree_complexe(zB,u,Size);
                  Couleur(Jaune);
                  Segment(zA,zB);
       end;

        Pause;



end;


Procedure Question2;
begin
     Efface;
     Writeln('+---------------------- Question n°2 -------------------------------+');
     Writeln('¦                                                                   ¦');
     Writeln('¦                                                                   ¦');
     Writeln('¦                                                                   ¦');
     Writeln('+-------------------------------------------------------------------+');
      Pause;
end;

{ Bloc principal }
begin
  Initgraphique;
  ModeTexte;
  Repeat
     Presentation;
     Question1;
     Ch:= ReadKey;
     case ch of
          '1':  Question1;
          '2':  Question2;
     end;
     Pause;
  until false;

