%%  $Id: pst-hertz.tex 1263 2026-05-29 08:05:14Z herbert $
%%
%% Package `pst-hertz.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.
%%
%% `pst-hertz' draw Hertzian Dipole with PSTricks
%%
%% Author:   Manuel Luque <manuel.luque27@gmail.com>
%%           Herbert VoÃŸ <hvoss@tug.org>   
%%
\csname PSTHertzLoaded\endcsname
\let \PSTHERTZLoaded\endinput
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTXKeyLoaded\endinput \else\input pst-xkey.tex\fi

\def\fileversion{0.1}
\def\filedate{2026/05/29}
\message{`PST' v\fileversion, \filedate}
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax

\pstheader{pst-math.pro}

\pst@addfams{pst-hertz}
\define@key[psset]{pst-hertz}{lambda}{\def\psk@hertz@L{#1 }} % longueur d'onde en m (1 pixel=1 m)
\define@key[psset]{pst-hertz}{t}{\def\psk@hertz@t{#1 }} % date en fraction de période de 0 à 100
\define@key[psset]{pst-hertz}{ScaleFactor}{\def\psk@hertz@ScaleFactor{#1 }}
\define@key[psset]{pst-hertz}{h}{\edef\psk@hertz@h{#1 }} % pas de l'itération (RK-4)
\define@key[psset]{pst-hertz}{FieldLines}{\edef\psk@hertz@FieldLines{#1 }} % nombre de lignes dans lambda/2
\define@boolkey[psset]{pst-hertz}[Pst@]{BiColorLines}[true]{} %
\define@boolkey[psset]{pst-hertz}[Pst@]{Ez}[true]{} %
\define@boolkey[psset]{pst-hertz}[Pst@]{DrawArrows}[true]{} %draw the arrows
% filling the space between the lines
\define@boolkey[psset]{pst-hertz}[Pst@]{FillSpace}[true]{}
\define@boolkey[psset]{pst-hertz}[Pst@]{DrawLines}[true]{}
\define@boolkey[psset]{pst-hertz}[Pst@]{HSBFill}[true]{}
%
\psset[pst-hertz]{lambda=100,t=0,h=1,ScaleFactor=1,
  BiColorLines=false,Ez=true,FieldLines=6,DrawArrows=true,
  FillSpace=false,DrawLines=true,HSBFill=false}
%
\def\psHertzDipole{\def\pst@par{}\pst@object{pshertz}}
\def\pshertz@i{%
\begin@SpecialObj
\addto@pscode{
100 dict begin
0 0 translate
/c 3e8 def % light speed
/epsilon0 8.8542e-12 def
/Cste 1 4 Pi mul epsilon0 mul Div def
/lambda \psk@hertz@L def % choix de la longueur d'onde
/h \psk@hertz@h def
/nFL \psk@hertz@FieldLines def
/colorLines \ifPst@BiColorLines true \else false \fi def 
/omega c 2 Pi mul mul lambda Div def %
/T 2 Pi mul omega Div def
/dt T 100 div def
/t' {t r c Div sub } def
/p {omega t' mul COS} def
/p' {omega t' mul SIN omega mul neg} def
/p" {omega dup mul neg p mul} def
/r {x dup mul y dup mul add z dup mul add sqrt} def
/Ex { x z mul
      3 p' mul c Div r 4 exp Div
      p" c 2 exp Div r 3 exp Div add
      3 p mul r 5 exp Div add
      mul
    } def
%% y=0 => Ey=0 %%
/Ey { y z mul
      3 p' mul c Div r 4 exp Div
      p"  c 2 exp Div r 3 exp Div add
      3 p mul r 5 exp Div add
      mul
    } def
/Ez { p" neg c 2 exp Div r Div
      p' c Div r 2 exp Div sub
      p r 3 exp Div sub
      z 2 exp
      3 p' mul c Div r 4 exp Div
      p" c 2 exp Div r 3 exp Div add
      3 p mul r 5 exp Div add
      mul
      add
    } def
/E {Ex dup mul Ez dup mul add sqrt} def
/RK4 { % Runge Kutta 4
 x0 z0 /z exch def /x exch def /Ez1 Ez def /Ex1 Ex def
 x0 Ex1 E Div h 2 Div mul add
 z0 Ez1 E Div h 2 Div mul add
  /z exch def /x exch def /Ez2 Ez def /Ex2 Ex def
 x0 Ex2 E Div h 2 Div mul add
 z0 Ez2 E Div h 2 Div mul add
 /z exch def /x exch def /Ez3 Ez def /Ex3 Ex def
 x0 Ex3 E Div h 2 Div mul add
 z0 Ez3 E Div h 2 Div mul add
  /z exch def /x exch def /Ez4 Ez def /Ex4 Ex def
 /X x0 Ex1 6 Div Ex2 3 Div add Ex3 3 Div add Ex4 6 Div add E Div h mul add def % x
 /Z z0 Ez1 6 Div Ez2 3 Div add Ez3 3 Div add Ez4 6 Div add E Div h mul add def % z
 }
 def
% dessin d'une flèche
/fleche {
 4 dict begin
 /y2 exch def /x2 exch def
 /y1 exch def /x1 exch def
  gsave
  x2 y2 moveto
  y2 y1 sub x2 x1 sub atan rotate
   1 CLW mul  2 CLW mul rlineto
  -5 CLW mul -2 CLW mul rlineto
   5 CLW mul -2 CLW mul rlineto
  closepath
  fill
  grestore
 end
} def
/cm {\psk@hertz@ScaleFactor mul} bind def % echelle
/y 0 def
/t dt \psk@hertz@t mul def
t T ge {/t t T sub def} if
/clMax nFL 1 sub def
/dl lambda nFL 4 mul idiv def
%
/TableauLignes [ % datas
-5 4 19 {/K exch def
/cl 0 def
/lambda0 lambda 8 div K mul def
lambda0 lambda 8 div sub dl lambda0 lambda 8 div add{/xi exch c t mul add def
cl clMax le { %
/zi 0 def
/z0 zi def /x0 xi def
/z zi def /x xi def
/Ezi Ez def
 Ezi 0 lt {/sens -1 def}{/sens 1 def} ifelse
 /L [
 {
 RK4
X Z
/x X def /z Z def
sens -1 eq {z 0 gt Ez 0 gt and {exit} if }{z 0 lt Ez 0 lt and {exit} if} ifelse
X 0.5 le {exit} if
/x0 X def /z0 Z def
 } loop
  ] def
L 0 get L L length 2 sub get ge {
[L aload pop
L length 2 sub -2 2 {/i exch def
L i get L i 1 sub get neg
} for
]
} if
} if
/cl cl 1 add def
} for
} for
 ] def
% les cercles d'onde de largeur = lambda/2
\ifPst@HSBFill
gsave
/iC 1 def
t T 2 div le {
 0 0 lambda 0.5 mul c t mul add cm 0 360 arc 1 6 div 0.8 1 sethsbcolor fill
 }{
 0 0 lambda 0.5 mul c t mul add cm 0 360 arc iC 6 div 0.8 1 sethsbcolor fill
 } ifelse
0 lambda 0.5 mul 2 lambda mul {/lw exch c t mul add cm def
  /iC iC 1 add def
newpath
    lw 0 moveto
    0 0 lw 0 360 arc
    lw 0.5 lambda mul cm add 0 moveto
    0 0 lw 0.5 lambda mul cm add 0 -360 arcn
closepath
  iC 6 div 0.8 1 sethsbcolor
  fill
   } for
grestore
\fi
% le remplissage des espaces entre les lignes
\ifPst@FillSpace
/NbLignes TableauLignes length 1 sub def
 gsave
/compteur 0 def
TableauLignes length 1 sub -1 1 {/j exch def
/Ligne1 TableauLignes j get def
newpath
/x Ligne1 0 get def /z Ligne1 1 get def
 x cm z cm moveto
0 2 Ligne1 length 2 sub {/pt exch def
Ligne1 pt get cm Ligne1 pt 1 add  get cm lineto
} for
%
/Ligne2 TableauLignes j 1 sub get def
/x Ligne2 Ligne2 length 2 sub get def /z Ligne2 Ligne2 length 1 sub get def
 x cm z cm moveto
Ligne2 length 2 sub -2 1  {/pt exch def
Ligne2 pt get cm Ligne2 pt 1 sub get cm lineto
} for
closepath
\ifPst@HSBFill
 j NbLignes div 0.8 1 sethsbcolor
 \else
compteur 2 mod 0 eq {\pst@usecolor\pshatchcolor}{\pst@usecolor\psfillcolor} ifelse
\fi
fill
/compteur compteur 1 add def
} for
grestore
 gsave
/compteur 0 def
TableauLignes length 1 sub -1 1 {/j exch def
/Ligne1 TableauLignes j get def
newpath
/x Ligne1 0 get neg def /z Ligne1 1 get def
 x cm z cm moveto
0 2 Ligne1 length 2 sub {/pt exch def
Ligne1 pt get neg cm Ligne1 pt 1 add  get cm lineto
} for
%
/Ligne2 TableauLignes j 1 sub get def
/x Ligne2 Ligne2 length 2 sub get neg def /z Ligne2 Ligne2 length 1 sub get def
 x cm z cm moveto
Ligne2 length 2 sub -2 1  {/pt exch def
Ligne2 pt get neg cm Ligne2 pt 1 sub get cm lineto
} for
closepath
\ifPst@HSBFill
 j NbLignes div 0.8 1 sethsbcolor
 \else
compteur 2 mod 0 eq {\pst@usecolor\pshatchcolor}{\pst@usecolor\psfillcolor} ifelse
\fi
fill
/compteur compteur 1 add def
} for
grestore
\fi
% le tracé des lignes
\ifPst@DrawLines
gsave
0 1 TableauLignes length 1 sub {/j exch def
/Ligne TableauLignes j get def
/x Ligne 0 get def /z Ligne 1 get def
z 0 gt Ez 0 ge and{colorLines {\pst@usecolor\pslinecolor} if}{colorLines {\pst@usecolor\psdoublecolor} if} ifelse
newpath
Ligne 0 get cm Ligne 1 get cm moveto
0 2 Ligne length 2 sub {/pt exch def
Ligne pt get cm Ligne pt 1 add  get cm lineto
} for
closepath
stroke
newpath
Ligne 0 get neg cm Ligne 1 get cm moveto
0 2 Ligne length 2 sub {/pt exch def
Ligne pt get neg cm Ligne pt 1 add  get cm lineto
} for
closepath
stroke
} for
grestore
\fi
% dessin des flèches
/LesFleches {
0 1 TableauLignes length 1 sub {/j exch def
/Ligne TableauLignes j get def
/x Ligne 0 get def /z Ligne 1 get def
z 0 gt Ez 0 ge and{colorLines {\pst@usecolor\pslinecolor} if}{colorLines {\pst@usecolor\psdoublecolor} if} ifelse
Ligne length 10 ge {
Ligne 2 get cm Ligne 3 get
Ligne 0 get cm Ligne 1 get
fleche
Ligne 2 get cm neg Ligne 3 get
Ligne 0 get cm neg Ligne 1 get
fleche
/start Ligne length 3 idiv def
start 2 mod 1 eq {/start start 1 add def}if
Ligne start 2 add get cm  Ligne start 3 add get cm
Ligne start get cm Ligne start 1 add get cm
fleche
Ligne start 2 add get cm  neg Ligne start 3 add get cm
Ligne start get cm neg Ligne start 1 add get cm
fleche
/start Ligne length 3 idiv 2 mul def
start 2 mod 1 eq {/start start 1 add def}if
Ligne start 2 add get cm  Ligne start 3 add get cm
Ligne start get cm Ligne start 1 add get cm
fleche
Ligne start 2 add get cm  neg Ligne start 3 add get cm
Ligne start get cm neg Ligne start 1 add get cm
fleche
} if
} for
} def
\ifPst@DrawArrows
LesFleches
\fi
% dessin de Ez(x,t)
\ifPst@Ez
gsave
0.5 0 0 setrgbcolor
2 setlinewidth
newpath
/x 1 def /z 0 def
x cm Ez 1e6 mul moveto
1 1 4 lambda mul {/x exch def
x cm Ez 1e6 mul lineto
} for
stroke
grestore
\fi
% le plus et le moins
gsave
2 setlinewidth
/t' t def
p 0 ge {/signe_p 1 def}{/signe_p -1 def } ifelse
/plus {0 p 5 mul 20 signe_p mul add moveto 0 -10 p mul rlineto
       5 p mul 20 signe_p mul moveto -10 p mul 0 rlineto 1 0 0 setrgbcolor} def
/moins {5 p mul -20 signe_p mul moveto -10 p mul 0 rlineto 0 0 1 setrgbcolor} def
 plus stroke moins stroke
grestore
0 setgray
% les graduations en fraction de lambda/4
%gsave
%2 setlinewidth
%0 lambda 4 div 3 lambda mul {/L exch cm def
%            L -5 moveto 0 10 rlineto stroke
%            }
%for
%grestore
% affichage du temps
/Times-Roman findfont
 12 scalefont
 setfont
 /MG 72 def
 /LigneSuivante
  { currentpoint 16 sub
  exch pop
  MG exch
  moveto } def
 /chaine 30 string def
 /imprime {chaine cvs show } def
0 150 moveto ( t=) imprime t 100 mul T div cvi 100 div imprime ( T ) imprime
end
 }% fin du code ps
\end@SpecialObj
}%

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