%% Package `pst-rubans.tex'
%%
%% This program can be redistributed and/or modified under
%% the terms of the LaTeX Project Public License Distributed
%% from CTAN archives in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-rubans' is a PSTricks package for 
%%   drawing 3 dimensional bands.
%%
%%
%% Authors  :   Manuel Luque <Manuel.Luque27@gmail.com>
%%              Herbert Voss <hvoss@tug.org>
%%
\csname PSTRubansLoaded\endcsname
\let\PSTRubansLoaded\endinput
%
% Require PSTricks and pst-solides3d
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTGradLoaded\endinput \else\input pst-solides3d.tex\fi
\ifx\PSTXKeyLoaded\endinput \else\input pst-xkey.tex\fi
%
\def\fileversion{1.2}
\def\filedate{2011/02/10}
%
\message{`PST-Rubans' v\fileversion, \filedate\space (ML/CJ/DG/HV)}
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
%
\pst@addfams{pst-rubans}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Definition des differentes variables pour PSTricks
%% ruban en helice circulaire
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\define@key[psset]{pst-rubans}{dZ}{\def\pst@rubans@dZ{#1}} % hauteur du ruban
\psset[pst-rubans]{dZ=0.5} % hauteur du ruban
\define@key[psset]{pst-rubans}{spires}{\def\pst@rubans@spires{#1}} %
\psset[pst-rubans]{spires=10} % nombre de spires d'un ruban
\define@key[psset]{pst-rubans}{rubans}{\def\pst@rubans@rubans{#1}} %
\psset[pst-rubans]{rubans=1} % nombre de spires d'un ruban

\def\pshelices{\pst@object{pshelices}}
%% usage : \pshelices[options](x,y,z)
\def\pshelices@i{\@ifnextchar({\pshelices@ii}{\pshelices@ii(0,0,0)}}
\def\pshelices@ii(#1,#2,#3){%
  \pst@killglue%
  \begingroup%
  \use@par%
\pstVerb{
/dz \pst@rubans@dZ\space def
/initvar_SpiralHelice {
  /rubans \pst@rubans@rubans\space def
  /phase {360 rubans div} bind def
  /Rayon \pst@solides@R\space def
  /Hauteur \pst@solides@h\space def
  /PHI 0 def
  /x@0 Rayon PHI cos mul def
  /y@0 Rayon PHI sin mul def
  /z@0 0 def
  /pulsation {6.28319 Hauteur div \pst@rubans@spires\space mul} bind def
  /x@1 {Rayon t@ pulsation mul 57.295 mul PHI add cos mul} def
  /y@1 {Rayon t@ pulsation mul 57.295 mul PHI add sin mul} def
  /z@1 {t@} def
  /dA {Hauteur \pst@solides@resolution\space div} bind def
  /tableau_des_sommets [
   rubans {
      dA dA Hauteur{/t@ exch def
                 x@0 y@0 z@0
                 x@1 y@1 z@1
                 x@1 y@1 z@1 dz add
                 x@0 y@0 z@0 dz add
                 /x@0 x@1 def
                 /y@0 y@1 def
                 /z@0 z@1 def
      } for
    /PHI PHI phase add def
    /x@0 Rayon PHI cos mul def
    /y@0 Rayon PHI sin mul def
    /z@0 0 def
   } repeat ] def
  /Sommets {tableau_des_sommets aload pop} def
  /NbrePoints tableau_des_sommets length 3 div cvi def
  /Faces  {0 4 NbrePoints 4 sub {
            /Ni exch def
            [ Ni Ni 1 add  Ni 2 add Ni 3 add]
          } for
  } def
  /Faces_internes {0 4 NbrePoints 4 sub {
      /Ni exch def
      [Ni 3 add Ni 2 add Ni 1 add Ni]
    } for
  } def
} def
initvar_SpiralHelice
}%
%\psSolid[object=new,sommets=Sommets,fillcolor=\psincolor,faces={Faces_internes}](#1,#2,#3)%
  \psSolid[object=new,sommets=Sommets,faces={Faces},hollow](#1,#2,#3)%
  \endgroup%
  \ignorespaces%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ruban en helice torique
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\define@key[psset]{pst-rubans}{dPHI}{\def\pst@rubans@dPHI{#1}} % hauteur du ruban
\psset[pst-rubans]{dPHI=5} % hauteur du ruban en degrés

\def\psSpiralRing{\pst@object{psSpiralRing}}
%% usage : \psSpiralRing[options]
\def\psSpiralRing@i{\@ifnextchar({\psSpiralRing@ii}{\psSpiralRing@ii(0,0,0)}}
\def\psSpiralRing@ii(#1,#2,#3){%
%  \pst@killglue%
  \begingroup%
  \use@par%
  \pstVerb{%
 /ri \pst@solides@rO\space def % rayon intérieur
 /rm \pst@solides@rI\space def % rayon moyen
 /spires \pst@rubans@spires\space def
 /dPHI \pst@rubans@dPHI\space def
 /initvar_SpiralRing {
   /THETA {PHI spires 2 mul mul} def
   /x@ {rm ri THETA cos mul add PHI cos mul} def
         /y@ {rm ri THETA cos mul add PHI sin mul} def
         /z@ {ri THETA sin mul} def
         /dt@ {360 \pst@solides@resolution\space div} bind def
         /PHI 0 def
         /tableau_des_sommets [
          0 dt@ 360 dt@ sub{/t@ exch def
                    /PHI t@ def /THETA0 THETA def
                     x@ y@ z@
                     /PHI t@ dt@ add def /THETA1 THETA def
                     x@ y@ z@ %/x1 x def /y1 y def /z1 z def % S2
                     /PHI PHI dPHI add def
                     rm ri THETA1 cos mul add PHI cos mul
                     rm ri THETA1 cos mul add PHI sin mul
                     ri THETA1 sin mul                 % S3
                     /PHI PHI dt@ sub def
                     rm ri THETA0 cos mul add PHI cos mul
                     rm ri THETA0 cos mul add PHI sin mul
                     ri THETA0 sin mul  % S4
                  } for
                  ]
           def
         /Sommets {tableau_des_sommets aload pop} def
         /NbrePoints tableau_des_sommets length 3 div cvi def
        /Faces_internes  {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [ Ni Ni 1 add  Ni 2 add Ni 3 add]
                                     } for
              } def
        /Faces {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [Ni 3 add Ni 2 add Ni 1 add Ni]
                                     } for
             } def
} def
initvar_SpiralRing
}%
%\psSolid[object=new,sommets=Sommets,fillcolor=\psincolor,faces={Faces_internes}](#1,#2,#3)%
\psSolid[object=new,sommets=Sommets,faces={Faces},hollow](#1,#2,#3)%
  \endgroup%
  \ignorespaces}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ruban en helice spherique
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\def\psSphericalSpiral{\pst@object{psSphericalSpiral}}
%% usage : \psSphericalSpiral[options]
\def\psSphericalSpiral@i{\@ifnextchar({\psSphericalSpiral@ii}{\psSphericalSpiral@ii(0,0,0)}}
\def\psSphericalSpiral@ii(#1,#2,#3){%
  \pst@killglue%
  \begingroup%
  \use@par%
\pstVerb{%
/initvar_SpiralSpherical {
         /Rayon \pst@solides@R\space def
         /spires \pst@rubans@spires\space def
         /dPHI \pst@rubans@dPHI\space def
         /THETA {PHI spires 2 mul mul} def
         /x@ {Rayon THETA cos mul PHI cos mul} def
         /y@ {Rayon THETA sin mul PHI cos mul} def
         /z@ {Rayon PHI sin mul} def
         /dt@ {180 \pst@solides@resolution\space div} bind def
         /PHI -90 def
         x@ y@ z@ /x0 x@ def /y0 y@ def /z0 z@ def % S1
         /tableau_des_sommets [
          -90 dt@ 90 dPHI sub{/t@ exch def
                    /PHI t@ def /THETA0 THETA def
                     x@ y@ z@
                     /PHI t@ dt@ add def /THETA1 THETA def
                     x@ y@ z@ %/x1 x def /y1 y def /z1 z def % S2
                     /PHI PHI dPHI add def
%                     x1 y1 z                             % S3
                     Rayon THETA1 cos mul PHI cos mul
                     Rayon THETA1 sin mul PHI cos mul
                     z@
                     /PHI PHI dt@ sub def
                     Rayon THETA0 cos mul PHI cos mul
                     Rayon THETA0 sin mul PHI cos mul
                     z@  % S4
                  } for
                  ]
           def
         /Sommets {tableau_des_sommets aload pop} def
         /NbrePoints tableau_des_sommets length 3 div cvi def
        /Faces  {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [ Ni Ni 1 add  Ni 2 add Ni 3 add]
                                     } for
              } def
        /Faces_internes {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [Ni 3 add Ni 2 add Ni 1 add Ni]
                                     } for
             } def
} def
initvar_SpiralSpherical
}%
%\psSolid[object=new,sommets=Sommets,fillcolor=\psincolor,faces={Faces_internes}](#1,#2,#3)%
\psSolid[object=new,sommets=Sommets,faces={Faces},hollow](#1,#2,#3)%
  \endgroup%
  \ignorespaces%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ruban en helice sur un paraboloide
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\define@key[psset]{pst-rubans}{p}{\def\pst@rubans@p{#1}} % parametre de la parabole
\psset[pst-rubans]{p=2}

\def\psSpiralParaboloid{\pst@object{psSpiralParaboloid}}
%% usage : \psSpiralParaboloid[options]
\def\psSpiralParaboloid@i{\@ifnextchar({\psSpiralParaboloid@ii}{\psSpiralParaboloid@ii(0,0,0)}}
\def\psSpiralParaboloid@ii(#1,#2,#3){%
%  \pst@killglue%
  \begingroup%
  \use@par%
\pstVerb{%
         /dz@ \pst@rubans@dZ\space def % hauteur du ruban
         /p@ {\pst@rubans@p\space 2 mul} bind def % paramètre de la parabole x 2
         /Hauteur \pst@solides@h\space def
/initvar_SpiralParaboloid {
         /pulsation {6.28319 Hauteur div \pst@rubans@spires\space mul} bind def
         /x@ {z@ p@ mul sqrt t@ pulsation mul 57.295 mul cos mul} def
         /y@ {z@ p@ mul sqrt t@ pulsation mul 57.295 mul sin mul} def
         /dH {Hauteur \pst@solides@resolution\space div} bind def
         /tableau_des_sommets [
          0 dH Hauteur {/H@ exch def
                        /z@ H@ def
                        /t@ H@ def
                     x@ y@ z@   % S1
                       /t@ t@ dH add def
                       /z@ t@ def
                     x@ y@ z@   % S2
                     /z@ z@ dz@ add def
                     x@ y@ z@  % S3
                       /z@ H@ dz@ add def
                       /t@ H@ def
                     x@ y@ z@   % S4
                  } for
                  ]
           def
         /Sommets {tableau_des_sommets aload pop} def
         /NbrePoints tableau_des_sommets length 3 div cvi def
        /Faces  {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [ Ni Ni 1 add  Ni 2 add Ni 3 add]
                                     } for
              } def
        /Faces_internes {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [Ni 3 add Ni 2 add Ni 1 add Ni]
                                     } for
             } def
} def
initvar_SpiralParaboloid
}%
%\psSolid[object=new,sommets=Sommets,fillcolor=\psincolor,faces={Faces_internes}](#1,#2,#3)%
\psSolid[object=new,sommets=Sommets,faces={Faces},hollow](#1,#2,#3)%
  \endgroup%
  \ignorespaces%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\psSpiralCone{\pst@object{psSpiralCone}}
%% usage : \psSpiralCone[options](x,y,z)
\def\psSpiralCone@i{\@ifnextchar({\psSpiralCone@ii}{\psSpiralCone@ii(0,0,0)}}
\def\psSpiralCone@ii(#1,#2,#3){%
  \begingroup%
  \use@par%
\pstVerb{/dz \pst@rubans@dZ\space def
/initvar_SpiralHelice_Conique {
         /rubans \pst@rubans@rubans\space def
         /phase {360 rubans div} bind def
         /Rayon \pst@solides@R\space def
         /Hauteur \pst@solides@h\space def
         /PHI 0 def
         /t@0 Hauteur 2 div neg def
         /x@0 Rayon Hauteur 2 div div t@0 mul PHI cos mul def
         /y@0 Rayon Hauteur 2 div div t@0 mul PHI sin mul def
         /z@0 t@0 def
         /pulsation {6.28319 Hauteur div \pst@rubans@spires\space mul} bind def
         /x@1 {Rayon Hauteur 2 div div t@ mul t@ pulsation mul 57.295 mul PHI add cos mul} def
         /y@1 {Rayon Hauteur 2 div div t@ mul t@ pulsation mul 57.295 mul PHI add sin mul} def
         /z@1 {t@} def
         /dA {Hauteur \pst@solides@resolution\space div} bind def
         /tableau_des_sommets [
             rubans {
          Hauteur 2 div neg dA Hauteur 2 div {/t@ exch def
                   t@ abs dA gt {
                     x@0 y@0 z@0 % S0
                     x@1 y@1 z@1 % S1
                     /COEFF z@1 dz add z@1 div def
                     x@1 COEFF mul y@1 COEFF mul z@1 dz add % S2
                     x@0 COEFF mul y@0 COEFF mul z@0 dz add % S3
                     /x@0 x@1 def
                     /y@0 y@1 def
                     /z@0 z@1 def
                     } if
                  } for
          /PHI PHI phase add def
         /t@0 Hauteur 2 div neg def
         /x@0 Rayon Hauteur 2 div div t@0 mul PHI cos mul def
         /y@0 Rayon Hauteur 2 div div t@0 mul PHI sin mul def
         /z@0 t@0 def
          } repeat
                  ]
           def
         /Sommets {tableau_des_sommets aload pop} def
         /NbrePoints tableau_des_sommets length 3 div cvi def
        /Faces  {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [ Ni Ni 1 add  Ni 2 add Ni 3 add]
                                     } for
              } def
        /Faces_internes {0 4 NbrePoints 4 sub {
                 /Ni exch def
               [Ni 3 add Ni 2 add Ni 1 add Ni]
                                     } for
             } def
} def
initvar_SpiralHelice_Conique
}%
\psSolid[object=new,sommets=Sommets,faces={Faces},hollow](#1,#2,#3)%
  \endgroup%
  \ignorespaces%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`\@=\PstAtCode\relax
\endinput
