Puzzle de Pythagore
Posté : dim. 30 sept. 2012, 11:55
Bonjour,
Ce n'est certes pas inédit, mais je ne l'ai pas trouvé codé en asymptote.
Je prends toute amélioration de mon code de goret
a+
Ce n'est certes pas inédit, mais je ne l'ai pas trouvé codé en asymptote.
Je prends toute amélioration de mon code de goret
a+
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***
- CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
- // Extensions
- import geometry;
- import patterns;
- unitsize(5mm);
- // Longueurs des côtés de l'angle droit : à renseigner !
- real l1=.4*15,l2=.4*8;
- real l3=sqrt(l1^2+l2^2);
- triangle t;
- // Test pour partager en 4 pièces le "bon" carré
- if (l1 > l2)
- {t=triangleabc(l3,l1,l2);}
- else
- {t=triangleabc(l3,l2,l1);}
- point pA=t.VA, pB=t.VB, pC=t.VC;
- // Hypoténuse parallèle à l'axe des abscisses
- transform r=rotate(aTan(length(pC-pA)/length(pB-pA))-180,pA);
- triangle t=r*t;
- point pA=r*pA, pB=r*pB, pC=r*pC;
- path carre1=square(pB,pA), carre2=square(pA,pC);
- point pO1=rotate(90,(pB+pA)/2)*pA;
- point pO2=rotate(90,(pA+pC)/2)*pC;
- point pO3=rotate(90,(pC+pB)/2)*pB;
- point pF=rotate(-90,pC)*pA, pG=rotate(90,pA)*pC;
- line d1=perpendicular(pO2,line(t.BC)), d2=perpendicular(pO2,d1);
- point pP1=intersectionpoint(d1,segment(pA,pC)), pP2=intersectionpoint(d1,segment(pF,pG)),
- pP3=intersectionpoint(d2,segment(pC,pF)), pP4=intersectionpoint(d2,segment(pA,pG));
- // Pièces du puzzle
- path piece1=carre1,
- piece2=pA--pP1--pO2--pP4--cycle, piece3=pC--pP3--pO2--pP1--cycle,
- piece4=pF--pP2--pO2--pP3--cycle, piece5=pG--pP4--pO2--pP2--cycle;
- // Puzzle assemblé
- path puzzle1=shift(pO3-pO1)*piece1,
- puzzle2=shift(pC-pO2)*piece2, puzzle3=shift(pB-pO2)*piece3,
- puzzle4=shift((rotate(-90,pB)*pC)-pO2)*piece4, puzzle5=shift(rotate(90,pC)*pB-pO2)*piece5;
- // // Version couleurs
- // filldraw(piece1,lightgray);
- // filldraw(piece2,lightred);
- // filldraw(piece3,lightgreen);
- // filldraw(piece4,lightyellow);
- // filldraw(piece5,lightblue);
- // filldraw(puzzle1,lightgray);
- // filldraw(puzzle2,lightred);
- // filldraw(puzzle3,lightgreen);
- // filldraw(puzzle4,lightyellow);
- // filldraw(puzzle5,lightblue);
- // Version noir et blanc
- add("hachures1",hatch(H=1.5mm,dir=S,gray));
- add("hachures2",hatch(H=2.5mm,dir=E,gray));
- add("hachures3",hatch(H=1.5mm,dir=pC-pA,gray));
- add("hachures4",hatch(H=2.5mm,dir=pB-pA,gray));
- filldraw(piece1,lightgray);
- filldraw(piece2,pattern("hachures1"));
- filldraw(piece3,pattern("hachures2"));
- filldraw(piece4,pattern("hachures3"));
- filldraw(piece5,pattern("hachures4"));
- filldraw(puzzle1,lightgray);
- filldraw(puzzle2,pattern("hachures1"));
- filldraw(puzzle3,pattern("hachures2"));
- filldraw(puzzle4,pattern("hachures3"));
- filldraw(puzzle5,pattern("hachures4"));
- draw(t);
- perpendicularmark(t.AB,t.AC);