%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                           %%
%% This is file `pst-sphericaltrochoid.tex',                                 %%
%%                                                                           %%
%% IMPORTANT NOTICE:                                                         %%
%%                                                                           %%
%% Package `pst-sphericaltrochoid'                                           %%
%%                                                                           %%
%% Manuel Luque; Herbert VoÃŸ                                                 %%
%%                                                                           %%
%% 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-sphericaltrochoid' is a PSTricks tools                              %%
%%  Package to draw the spherical trochoid                                   %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\csname PSTSphericaltrochoid\endcsname
\let\PSTSphericaltrochoid\endinput

% Require PSTricks
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTSOLIDESIIIDLoaded\endinput\else\input pst-solides3d.tex\fi
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey\fi

\def\fileversion{0.01}
\def\filedate{2025/12/25}
\message{`PST-shpericaltrochoid' v\fileversion, \filedate\space (ml,hv)}

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax

\pst@addfams{pst-sphericaltrochoid}

\define@key[psset]{pst-sphericaltrochoid}{rB}{\edef\pst@sphericaltrochoid@rB{#1 }}
\psset[pst-sphericaltrochoid]{rB=1}% radius of the base circle

\define@key[psset]{pst-sphericaltrochoid}{rR}{\edef\pst@sphericaltrochoid@rR{#1 }}
\psset[pst-sphericaltrochoid]{rR=1}% radius of the rolling disk

\define@key[psset]{pst-sphericaltrochoid}{rG}{\edef\pst@sphericaltrochoid@rG{#1 }}
\psset[pst-sphericaltrochoid]{rG=1}% distance from the generating point to the center of the rolling disk

\define@key[psset]{pst-sphericaltrochoid}{w}{\edef\pst@sphericaltrochoid@w{#1 }}
\psset[pst-sphericaltrochoid]{w=90}% angle between the x-y plane and the plane of the rolling disk

\define@key[psset]{pst-sphericaltrochoid}{t}{\edef\pst@sphericaltrochoid@t{#1 }}
\psset[pst-sphericaltrochoid]{t=30}% angular displacement of the rolling disk along the edge of the base circle

\define@key[psset]{pst-sphericaltrochoid}{tmax}{\edef\pst@sphericaltrochoid@tmax{#1 }}
\psset[pst-sphericaltrochoid]{tmax=360}% maximum angular displacement of the rolling disk along the edge of the base circle

\define@boolkey[psset]{pst-sphericaltrochoid}[Pst@sphericaltrochoid@]{Sphere}[true]{}
\psset[pst-sphericaltrochoid]{Sphere=true}

\pstheader{pst-nutation.pro}%  Use the one from nutation!

\addtosolideslistobject{parallel,meridian}

\def\psSphericalTrochoid{\def\pst@par{}\pst@object{psSphericalTrochoid}}
\def\psSphericalTrochoid@i{%
  \addbefore@par{solidmemory,lightsrc=viewpoint,resolution=360,
                 Decran=1000,viewpoint=500 0 30 rtp2xyz,linecolor=red}%
  \begin@SpecialObj
  \pnode( ! % le point de vue
         \pst@solides@viewpoint /ZpointVue ED /YpointVue ED /XpointVue ED
         /THETA {YpointVue XpointVue atan} bind def
         /PHI   {ZpointVue XpointVue dup mul YpointVue dup mul add sqrt atan} bind def
         /nXviewpoint THETA cos PHI cos mul def
         /nYviewpoint THETA sin PHI cos mul def
         /nZviewpoint PHI sin def
         /rB \pst@sphericaltrochoid@rB def
         /rR \pst@sphericaltrochoid@rR def
         /rG \pst@sphericaltrochoid@rG def
         /inclination \pst@sphericaltrochoid@w def
         inclination 180 ge {/inclination 179.9 def} if
         inclination 0 le {/inclination 0.1 def} if
         /hC rR rB inclination  cos mul sub inclination sin div def
         /Rsphere rB dup mul hC dup mul add rR dup mul sub rG dup mul add sqrt def
         /angleRotation {rB t mul rR div} def
% the coordinates of the point of the spherical strophoid
         /xG { t cos rB inclination cos rR rG angleRotation sin mul sub 
               mul sub mul rG t sin mul angleRotation cos mul sub } def
         /yG { t sin rB inclination cos rR rG angleRotation sin mul sub 
               mul sub mul rG t cos mul angleRotation cos mul add } def
         /zG {inclination sin rR rG angleRotation sin mul sub mul} def
% the coordinates of the center of the rolling circle
         /xCR {t cos rB rR inclination cos mul sub mul} def
         /yCR {t sin rB rR inclination cos mul sub mul} def
         /zCR rR inclination sin mul def
% normale au plan du cercle roulant
        /nRx {t cos inclination sin mul neg} def
        /nRy {t sin inclination sin mul neg} def
        /nRz {inclination cos neg} def
% coordonnées du point de contact
        /xCo {rB t cos mul} def
        /yCo {rB t sin mul} def
        /zCo 0 def
        0 0){factice}
  \psSolid[object=plan,definition=equation,args={[0 0 1 0] 90},name=monplan,action=none]%
  \psProjection[object=cercle,plan=monplan,args=0 0 rB,resolution=360,
                linecolor={[rgb]{0 0 0.5}},range=0 360,linewidth=0.1,
                fillstyle=solid,fillcolor=gray!40!cyan!40,opacity=0.5,
                visibility]
  \composeSolid
  \defFunction{SphericalTrochoid}(t){xG}{yG}{zG}%
  \psSolid[object=courbe,r=0,range=0 \pst@sphericaltrochoid@tmax,
           function=SphericalTrochoid,fillcolor=\pslinecolor,linewidth=0.07,linecolor=red]%
  \ifPst@sphericaltrochoid@Sphere
    \multido{\i=-90+30}{6}{%
      \psSolid[object=parallel,r=Rsphere,phi=\i,linecolor={[rgb]{0 0 0.5}}](0,0,hC)}%
    \multido{\i=0+30}{12}{%
      \psSolid[object=meridian,r=Rsphere,theta=\i,linecolor={[rgb]{0 0 0.5}}](0,0,hC)}%
    \psSolid[object=plan,definition=normalpoint,
             args={0 0 hC [nXviewpoint nYviewpoint nZviewpoint]},name=leplan,action=none]%
    \psProjection[object=cercle,plan=leplan,linecolor={[rgb]{0 0 0.5}},
                  args=0 0 Rsphere,range=0 360]%
  \fi
  \pstVerb{/t \pst@sphericaltrochoid@t def}%
  \psPoint(xCR,yCR,zCR){O}\psdot[linecolor=blue](O)
  \psPoint(xG,yG,zG){G}%
  \psline[linecolor=blue,linewidth=0.05](O)(G)%
  \psdot[linecolor=\pslinecolor,dotsize=0.2](G)
  \psSolid[object=plan,definition=normalpoint,args={xCR yCR zCR [nRx nRy nRz]},name=planC,action=none]%
  \psProjection[object=cercle,plan=planC,visibility,linecolor=blue,linewidth=0.1,
                args=0 0 rR,opacity=0.5,fillcolor=cyan!50,range=0 360,
                fillstyle=solid]
  \composeSolid
  \end@SpecialObj
  \ignorespaces
}%

\catcode`\@=\PstAtCode\relax
\endinput
 