Source PostScript (geom3d.pps)

Retour Texte non formaté
%% syntaxe : A k1 B k2 barycentre3d -> G, barycentre du systeme %% [(A, k1) (B, k2)] /barycentre3d { 4 dict begin /k2 exch def /B defpoint3d /k1 exch def /A defpoint3d A k1 mulv3d B k2 mulv3d addv3d 1 k1 k2 add div mulv3d end } def %% syntaxe : array isobarycentre3d --> G /isobarycentre3d { 2 dict begin /table exch def /n table length 3 idiv def table 0 getp3d 1 1 n 1 sub { table exch getp3d addv3d } for 1 n div mulv3d end } def %% syntaxe : M A alpha hompoint3d -> le point M' tel que AM' = alpha AM /hompoint3d { 3 dict begin /alpha exch def /A defpoint3d /M defpoint3d A M vecteur3d alpha mulv3d A addv3d end } def %% syntaxe : M A sympoint3d -> le point M' tel que AM' = -AM /sympoint3d { 2 dict begin /A defpoint3d /M defpoint3d A M vecteur3d -1 mulv3d A addv3d end } def %% syntaxe : A u translatepoint3d --> B image de A par la translation de vecteur u /translatepoint3d { addv3d } def /scaleOpoint3d { 6 dict begin /k3 exch def /k2 exch def /k1 exch def /z exch def /y exch def /x exch def k1 x mul k2 y mul k3 z mul end } def % syntaxe : M alpha_x alpha_y alpha_z rotateOpoint3d --> M' /rotateOpoint3d { 21 dict begin /RotZ exch def /RotY exch def /RotX exch def /Zpoint exch def /Ypoint exch def /Xpoint exch def /c1 {RotX cos} bind def /c2 {RotY cos} bind def /c3 {RotZ cos} bind def /s1 {RotX sin} bind def /s2 {RotY sin} bind def /s3 {RotZ sin} bind def /M11 {c2 c3 mul} bind def /M12 {c3 s1 mul s2 mul c1 s3 mul sub} bind def /M13 {c1 c3 mul s2 mul s1 s3 mul add} bind def /M21 {c2 s3 mul} bind def /M22 {s1 s2 mul s3 mul c1 c3 mul add} bind def /M23 {s3 s2 mul c1 mul c3 s1 mul sub} bind def /M31 {s2 neg} bind def /M32 {s1 c2 mul} bind def /M33 {c1 c2 mul} bind def M11 Xpoint mul M12 Ypoint mul add M13 Zpoint mul add M21 Xpoint mul M22 Ypoint mul add M23 Zpoint mul add M31 Xpoint mul M32 Ypoint mul add M33 Zpoint mul add end } def %% /ligne3d { %% [tableau de points3d] option --> trace la ligne brisée %% 1 dict begin %% tab3dto2d %% ligne %% end %% } def %% %% %% transforme un tableau de points 3d en tableau de points 2d %% /tab3dto2d { %% 2 dict begin %% /T exch def %% /n T length def %% [ T aload pop %% n 1 sub -1 n 3 idiv 2 mul %% { 1 dict begin %% /i exch def %% 3dto2d i 2 roll %% end } for ] %% end %% } def %% %% %% création du vecteur AB à partir de A et B %% /vecteur3d { %% xA yA zA xB yB zB %% 6 dict begin %% /zB exch def %% /yB exch def %% /xB exch def %% /zA exch def %% /yA exch def %% /xA exch def %% xB xA sub %% yB yA sub %% zB zA sub %% end %% }def %% %% %% produit vectoriel de deux vecteurs 3d %% /vectprod3d { %% x y z x' y' z' %% 6 dict begin %% /zp exch def %% /yp exch def %% /xp exch def %% /z exch def %% /y exch def %% /x exch def %% y zp mul z yp mul sub %% z xp mul x zp mul sub %% x yp mul y xp mul sub %% end %% } def %% %% %% produit scalaire de deux vecteurs 3d %% /scalprod3d { %% x y z x' y' z' %% 6 dict begin %% /zp exch def %% /yp exch def %% /xp exch def %% /z exch def %% /y exch def %% /x exch def %% x xp mul y yp mul add z zp mul add %% end %% } def %% %% %% syntaxe : [A1 ... An] (f) papply3d --> [f(A1) ... f(An)] %% /papply3d { %% 3 dict begin %% /fonction exch def %% /liste exch def %% /i 0 def %% [ %% liste length 3 idiv { %% liste i get %% liste i 1 add get %% liste i 2 add get %% fonction %% /i i 3 add store %% } repeat %% counttomark %% 0 eq %% {pop} %% {]} %% ifelse %% end %% } def /projxy { 3 dict begin /z exch def /y exch def /x exch def x y 0 end } def /projyz { 3 dict begin /z exch def /y exch def /x exch def 0 y z end } def /projxz { 3 dict begin /z exch def /y exch def /x exch def x 0 z end } def %% /getp3d { %% [tableau de points 3d] i --> donne le ième point du tableau %% 2 copy 2 copy %% 3 mul get %% 5 1 roll %% 3 mul 1 add get %% 3 1 roll %% 3 mul 2 add get %% } def %% %% %% création du point A à partir de xA yA yB et du nom /A %% /defpoint3d { %% xA yA zA /nom %% 1 dict begin %% /memo exch def %% [ 4 1 roll ] cvx memo exch %% end def %% }def %% %% %% (scalaire)*(vecteur 3d) Attention : dans l'autre sens ! %% /mulv3d { %% x y z lambda %% 4 dict begin %% /lambda exch def %% /z exch def %% /y exch def %% /x exch def %% x lambda mul %% y lambda mul %% z lambda mul %% end %% } def %% %% %% addition de deux vecteurs 3d %% /addv3d { %% x y z x' y' z' %% 6 dict begin %% /zp exch def %% /yp exch def %% /xp exch def %% /z exch def %% /y exch def %% /x exch def %% x xp add %% y yp add %% z zp add %% end %% } def %% %% /milieu3d { %% A B --> I le milieu de [AB] %% addv3d 0.5 mulv3d %% } def %% %% /polygone3d* { %% tableau de points3d %% tab3dto2d polygone* %% } def %% syntaxe : X Y x xplanmappoint --> x X Y /xplanmappoint { 3 1 roll } def %% syntaxe : X Y y zplanmappoint --> X y Y /yplanmappoint { exch } def %% syntaxe : X Y z zplanmappoint --> X Y z /zplanmappoint {} def