input geom2d;

beginfig(1);
    gddU := 1.5cm;
    A = Point(0,0);
    B = Point(2,0);
    C = Point(2,4);
    D = Point(0,4);
    ABCD = Polygone(A,B,C,D);
    Diag = Droite(B,D);
    A' = Point(0,2);
    B' = Point(2,2);
    P = Point(2,1.3);
    D_P = Droite(P,(0,Ordonnee(P)));
    D_AD = Droite(A,D);
    Q = IntersectionDroites(D_P,D_AD);
    Diag_Q = Droite(B,Q);
    P' = IntersectionDroites(D_P,Diag);
    Diag_P' = DroiteParallele(Diag_Q,P');
    Q' = IntersectionDroites(Diag_P',D_AD);
    D_Q' = Droite(Q',(Abscisse(B),Ordonnee(Q')));
    P'' = IntersectionDroites(D_Q',Diag);
    Diag_P'' = DroiteParallele(Diag_Q,P'');
    Q'' = IntersectionDroites(Diag_P'',D_AD);
    D_Q'' = Droite(Q'',(Abscisse(B),Ordonnee(Q'')));
    P''' = IntersectionDroites(D_Q'',Diag);
    E = Point(Abscisse(B),Ordonnee(P'''));
    D_A'E = Droite(A',E);
    D_BA' = Droite(B,A');
    D_Ppar = DroiteParallele(D_A'E,P);
    F = IntersectionDroites(D_BA',D_Ppar);
    P_1 = Point(Abscisse(B),Ordonnee(F));
    D_F = Droite(F,P_1);
    
    % representation
    trace ABCD; 
    trace Diag;
    trace Segment(A',B');
    drawoptions(avecCrayon(0.5,SandyBrown));
    trace Diag_Q;
    trace Diag_P';
    trace Diag_P'';
    drawoptions(avecCrayon(0.5,MediumSeaGreen));
    trace D_P;
    trace D_Q';
    trace D_Q'';
    drawoptions(avecCrayon(0.5,SkyBlue));
    trace D_A'E;
    trace D_Ppar;
    trace D_BA';
    trace D_F;
    drawoptions();
    marque.lrt "P";
    marque.llft "P'";
    marque.llft "P''";
    marque.llft "P'''";
    marque.llft "Q";
    marque.llft "Q'";
    marque.llft "Q''";
    trace Segment(F,P_1) avecCrayon(0.8,Crimson);
    marque.lrt "P_1";
    Fenetre(-0.5,-0.5,2.5,4.5);
endfig;
end.