/CylindricalPortionDict 100 dict def CylindricalPortionDict begin /facette { newpath Xfacette Yfacette Zfacette 3dto2d moveto theta 1 theta incrementANGLE add {% /theta1 exch def /Xpoint Rcylindre theta1 cos mul def /Ypoint Rcylindre theta1 sin mul def /Zpoint H def PointsApresTransformations 3dto2d lineto } for H 1 H incrementHAUTEUR add { /H1 exch def /Xpoint Rcylindre theta incrementANGLE add cos mul def /Ypoint Rcylindre theta incrementANGLE add sin mul def /Zpoint H1 def PointsApresTransformations 3dto2d lineto } for theta incrementANGLE add -1 theta {% /theta1 exch def /Xpoint Rcylindre theta1 cos mul def /Ypoint Rcylindre theta1 sin mul def /Zpoint H incrementHAUTEUR add def PointsApresTransformations 3dto2d lineto } for H incrementHAUTEUR add -1 H { /H1 exch def /Xpoint Rcylindre theta cos mul def /Ypoint Rcylindre theta sin mul def /Zpoint H1 def PointsApresTransformations 3dto2d lineto } for closepath} def /cylindricalportion { anglebegin incrementANGLE angleend incrementANGLE sub{% /theta exch def 0 incrementHAUTEUR Hcylindre incrementHAUTEUR sub {% /H exch def % newpath /X1 Rcylindre theta cos mul def /Y1 Rcylindre theta sin mul def /Z1 H def /Xpoint X1 def /Ypoint Y1 def /Zpoint Z1 def PointsApresTransformations /Zfacette ED /Yfacette ED /Xfacette ED % coordonnées du centre de la facette /Xpoint Rcylindre theta incrementANGLE 2 div add cos mul def /Ypoint Rcylindre theta incrementANGLE 2 div add sin mul def /Zpoint H incrementHAUTEUR 2 div add def PointsApresTransformations /Zcentre ED /Ycentre ED /Xcentre ED % Point sur l'axe du cylindre % à la même hauteur que le centre /Zpoint H incrementHAUTEUR 2 div add def /Xpoint 0 def /Ypoint 0 def PointsApresTransformations /zM1 ED /yM1 ED /xM1 ED % normale à la facette /xN Xcentre xM1 sub def /yN Ycentre yM1 sub def /zN Zcentre zM1 sub def % rayon vers point de vue /RXvue XpointVue Xcentre sub def /RYvue YpointVue Ycentre sub def /RZvue ZpointVue Zcentre sub def % test de visibilité /PSfacette xN RXvue mul yN RYvue mul add zN RZvue mul add def % vecteur centre de la facette vers la source de lumière /VxLight xLight Xcentre sub def /VyLight yLight Ycentre sub def /VzLight zLight Zcentre sub def % norme /normeL VxLight dup mul VyLight dup mul VzLight dup mul add add sqrt def /normeN xN dup mul yN dup mul zN dup mul add add sqrt def % produit scalaire /PSLight VxLight xN mul VyLight yN mul add VzLight zN mul add def /CosCouleur PSLight normeL normeN mul div ChangeSigne def condition { facette %H_S CosCouleur sethsbcolor fill nocolor toDraw } if } for } for } def /Face_superieure { % centre de la face supérieure /Xpoint 0 def /Zpoint Hcylindre def /Ypoint 0 def PointsApresTransformations /CzFaceSup ED /CyFaceSup ED /CxFaceSup ED % centre de la face inférieure /Xpoint 0 def /Zpoint 0 def /Ypoint 0 def PointsApresTransformations /CzFaceInf ED /CyFaceInf ED /CxFaceInf ED % Normale à la face supérieure /nXFaceSup CxFaceSup CxFaceInf sub def /nYFaceSup CyFaceSup CyFaceInf sub def /nZFaceSup CzFaceSup CzFaceInf sub def % rayon vers point de vue verd la face supérieure /RXvueSup XpointVue CxFaceSup sub def /RYvueSup YpointVue CyFaceSup sub def /RZvueSup ZpointVue CzFaceSup sub def % Visibilité face supérieure /PSfaceSup RXvueSup nXFaceSup mul RYvueSup nYFaceSup mul add RZvueSup nZFaceSup mul add def } def /FaceSup { /TableauxPoints [ anglebegin pas angleend {% on décrit le cercle /theta exch def [ /Xpoint Rcylindre theta cos mul def /Ypoint Rcylindre theta sin mul def /Zpoint Hcylindre def PointsApresTransformations 3dto2d ] } for ] def TableauxPoints 0 get aload pop moveto 0 1 TableauxPoints length 1 sub { /compteur exch def TableauxPoints compteur get aload pop lineto } for } def /Face_inferieure{ % centre de la face inférieure /Xpoint 0 def /Zpoint 0 def /Ypoint 0 def PointsApresTransformations /CzFaceInf ED /CyFaceInf ED /CxFaceInf ED % rayon de la face inférieure vers le point de vue /RXvueInf XpointVue CxFaceInf sub def /RYvueInf YpointVue CyFaceInf sub def /RZvueInf ZpointVue CzFaceInf sub def % centre de la face supérieure /Xpoint 0 def /Zpoint Hcylindre def /Ypoint 0 def PointsApresTransformations /CzFaceSup ED /CyFaceSup ED /CxFaceSup ED % Normale à la face inférieure /nXFaceInf CxFaceInf CxFaceSup sub def /nYFaceInf CyFaceInf CyFaceSup sub def /nZFaceInf CzFaceInf CzFaceSup sub def % Visibilité face inférieure /PSfaceInf RXvueInf nXFaceInf mul RYvueInf nYFaceInf mul add RZvueInf nZFaceInf mul add def } def /FaceInf { /TableauxPoints [ anglebegin pas angleend {% on décrit le cercle /theta exch def [ /Xpoint Rcylindre theta cos mul def /Ypoint Rcylindre theta sin mul def /Zpoint 0 def PointsApresTransformations 3dto2d ] } for ] def TableauxPoints 0 get aload pop moveto 0 1 TableauxPoints length 1 sub { /compteur exch def TableauxPoints compteur get aload pop lineto } for } def /Plat { % P1 /Xpoint Rcylindre anglebegin cos mul def /Ypoint Rcylindre anglebegin sin mul def /Zpoint 0 def PointsApresTransformations /Z1 ED /Y1 ED /X1 ED % P2 /Xpoint Rcylindre angleend cos mul def /Ypoint Rcylindre angleend sin mul def /Zpoint 0 def PointsApresTransformations /Z2 ED /Y2 ED /X2 ED % P3 /Xpoint Rcylindre angleend cos mul def /Ypoint Rcylindre angleend sin mul def /Zpoint Hcylindre def PointsApresTransformations /Z3 ED /Y3 ED /X3 ED % P4 /Xpoint Rcylindre anglebegin cos mul def /Ypoint Rcylindre anglebegin sin mul def /Zpoint Hcylindre def PointsApresTransformations /Z4 ED /Y4 ED /X4 ED /PlatDraw { newpath X1 Y1 Z1 3dto2d moveto X2 Y2 Z2 3dto2d lineto X3 Y3 Z3 3dto2d lineto X4 Y4 Z4 3dto2d lineto closepath } def %% centre de la face /xF {X1 X2 add X3 add X4 add 4 div} bind def /yF {Y1 Y2 Y3 Y4 add add add 4 div} bind def /zF {Z1 Z2 Z3 Z4 add add add 4 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 %% distance % /D {xV dup mul yV dup mul add zV dup mul add sqrt} 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 /PSplat xV xN mul yV yN mul add zV zN mul add neg def } def end %