/decoupage_cube { 100 dict begin %% le calcul des sommets du cube /m 3 def % nombre d'arêtes sur un sommet /n 4 def % nombre de côtés de chaque face %% les sommets %% abscisses /x1 {arete 2 div} bind def /x2 {x1 neg} bind def /x3 x2 def /x4 x1 def /x5 x1 def /x6 x2 def /x7 x2 def /x8 x1 def %% ordonnées /y1 {arete 2 div} bind def /y2 y1 def /y3 {y1 neg} bind def /y4 y3 def /y5 y1 def /y6 y1 def /y7 y3 def /y8 y3 def %% les cotes /z1 {arete 2 div} bind def /z2 z1 def /z3 z1 def /z4 z1 def /z5 {z1 neg} bind def /z6 z5 def /z7 z5 def /z8 z5 def %% les sommets : 8 sommets = 24 coordonnées /S [x1 y1 z1 % 0->2 x2 y2 z2 % 3->5 x3 y3 z3 % 6->8 x4 y4 z4 % 9->11 x5 y5 z5 % 12->14 x6 y6 z6 % 15->17 x7 y7 z7 % 18->20 x8 y8 z8 % 21->23 ] def /T1 [ % faces du tétraèdre 1 (4 5 6 8) 8 5 4 4 5 6 8 4 6 5 8 6 ] def /T2 [ % faces du tétraèdre 2 (4 6 7 8) 4 7 8 4 8 6 8 7 6 4 6 7 ] def /T3 [ % faces du tétraèdre 3 (1 4 5 6) 1 4 5 1 5 6 1 6 4 5 4 6 ] def /T4 [ % faces du tétraèdre 4 (3 4 7 6) 4 3 7 3 6 7 4 6 3 6 4 7] def /T5 [ % faces du tétraèdre 5 (1 2 3 6) 2 1 6 1 2 3 2 6 3 1 3 6 ] def /T6 [ % faces du tétraèdre 5 (4 1 6 3) 3 4 1 1 6 3 1 4 6 4 3 6 ] def % le dessin des tétraèdres /j 0 def 0 3 tetrahedron length 3 sub { % le dessin des triagles /i exch def tetrahedron i get 1 sub 3 mul /k exch def S k get /Xpoint exch def S k 1 add get /Ypoint exch def S k 2 add get /Zpoint exch def PointsApresTransformations /Z1 exch def /Y1 exch def /X1 exch def %% tetrahedron i 1 add get 1 sub 3 mul /k exch def S k get /Xpoint exch def S k 1 add get /Ypoint exch def S k 2 add get /Zpoint exch def PointsApresTransformations /Z2 exch def /Y2 exch def /X2 exch def %% tetrahedron i 2 add get 1 sub 3 mul /k exch def S k get /Xpoint exch def S k 1 add get /Ypoint exch def S k 2 add get /Zpoint exch def PointsApresTransformations /Z3 exch def /Y3 exch def /X3 exch def %% centre de la face /xF {X1 X2 add X3 add 3 div} bind def /yF {Y1 Y2 Y3 add add 3 div} bind def /zF {Z1 Z2 Z3 add add 3 div} bind def %% vecteur : centre de la face -> point de vue /xV {XpointVue xF sub } bind def /yV {YpointVue yF sub } bind def /zV {ZpointVue zF sub } bind def %% normale % les vecteurs de la face /V1x X2 X1 sub def /V1y Y2 Y1 sub def /V1z Z2 Z1 sub def /V2x X3 X2 sub def /V2y Y3 Y2 sub def /V2z Z3 Z2 sub def % le produit vectoriel /xN V1y V2z mul V1z V2y mul sub def /yN V1x V2z mul V1z V2x mul sub neg def /zN V1x V2y mul V1y V2x mul sub def % le produit scalaire des 2 vecteurs /PSfacette xV xN mul yV yN mul add zV zN mul add def condition { /facette { newpath % tracé de la facette X1 Y1 Z1 3dto2d moveto X2 Y2 Z2 3dto2d lineto X3 Y3 Z3 3dto2d lineto closepath } def facette tetrahedron T1 eq {% j 0 eq {1 1 0 setrgbcolor} if j 1 eq {0.9 0.9 0 setrgbcolor} if j 2 eq {0.8 0.8 0 setrgbcolor} if j 3 eq {0.7 0.7 0 setrgbcolor} if } if tetrahedron T2 eq {% j 0 eq {0 1 0 setrgbcolor} if j 1 eq {0.2 1 0.2 setrgbcolor} if j 2 eq {0.4 1 0.4 setrgbcolor} if j 3 eq {0.6 1 0.6 setrgbcolor} if } if tetrahedron T3 eq {% j 0 eq {1 1 0 setrgbcolor} if j 1 eq {1 0.2 0.2 setrgbcolor} if j 2 eq {1 0.8 0.8 setrgbcolor} if j 3 eq {0.5 0.5 1 setrgbcolor} if } if tetrahedron T4 eq {% j 0 eq {0 1 0 setrgbcolor} if j 1 eq {0.7 0.7 1 setrgbcolor} if j 2 eq {1 1 0.5 setrgbcolor} if j 3 eq {0.8 0.8 0.8 setrgbcolor} if } if tetrahedron T5 eq {% j 0 eq {1 0.2 0.2 setrgbcolor} if j 1 eq {1 0.5 1 setrgbcolor} if j 2 eq {0.7 0.7 1 setrgbcolor} if j 3 eq {0.8 0.8 0.8 setrgbcolor} if } if tetrahedron T6 eq {% j 0 eq {1 0.5 1 setrgbcolor} if j 1 eq {1 0.2 1 setrgbcolor} if j 2 eq {0.5 1 0.5 setrgbcolor} if j 3 eq {0.8 0.8 0.8 setrgbcolor} if } if fill Trace_arete } if /j j 1 add def } for end} def