% $Id: pst-electricfield.tex 479 2011-03-26 10:12:49Z herbert $
%% Package `pst-electricfield.tex'
%%
%% Manuel Luque
%% Jürgen Gilg
%% Patrice Megret
%% 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.
%%
%% A PSTricks related package to draw electric field lines
%% It uses the method from Euler
%%
\csname PSTElectricFieldLoaded\endcsname
\let\PSTElectricFieldLoaded\endinput
%
% Requires some packages
\ifx\PSTricksLoaded\endinput\else \input pstricks   \fi
\ifx\MultidoLoaded\endinput\else  \input multido.tex\fi
\ifx\PSTXKeyLoaded\endinput\else  \input pst-xkey   \fi
%
\def\fileversion{0.14}
\def\filedate{2011/03/26}
\message{`pst-electricfield' v\fileversion, \filedate\space (ml,jg,hv)}
%
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
%
\SpecialCoor
\pst@addfams{pst-electricfield}

%% prologue for postcript
\pstheader{pst-electricfield.pro}%

%% [q1 x1 y1 N1 plotCharge] [q2 x2 y2 N2 plotCharge] [...] etc
%% [charge, coordonnees, nombre de lignes, plotCircle]
%% number of lines and boolean for the circle are optional 
\define@key[psset]{pst-electricfield}{Q}[{[1 -2 0 10][1 1 0][1 0 1 15]}]{\def\psk@electricfieldQ{#1}}
\psset[pst-electricfield]{Q=[1 -2 0 10][1 1 0][1 0 1 15]}
\define@key[psset]{pst-electricfield}{N}[17]{\def\psk@electricfieldN{#1 }} %% par defaut 16 lignes
\psset[pst-electricfield]{N=17}
%% nombre de points du trace
\define@key[psset]{pst-electricfield}{points}[400]{\def\psk@electricfieldpoints{#1 }}
\psset[pst-electricfield]{points=400}
%% pas du trace
\define@key[psset]{pst-electricfield}{Pas}[0.025]{\def\psk@electricfieldPas{#1 }}
\psset[pst-electricfield]{Pas=0.025}
\define@key[psset]{pst-electricfield}{posArrow}[0.25]{\def\psk@ElectricFieldposArrow{#1 }}
\psset[pst-electricfield]{posArrow=0.25}
%
\def\tx@EFieldDict{ tx@EFieldDict begin }
%
\def\psElectricfield{\pst@object{psElectricfield}}
\def\psElectricfield@i{%
  \pst@killglue%
  \addbefore@par{radius=1mm}%
  \begin@OpenObj%
  \pssetlength\pst@dimb\psk@radius
  \addto@pscode{%
    \tx@EFieldDict
    /QXYN [\psk@electricfieldQ] def
    /ChargeRadius \pst@number\pst@dimb def
    /N \psk@electricfieldN def
    /NbrePoints \psk@electricfieldpoints def
    /Pas \psk@electricfieldPas def
    /posArrow \psk@ElectricFieldposArrow def
    /arrowscale { \psk@arrowscale } def
    /xUnit \pst@number\psxunit def
    /yUnit \pst@number\psyunit def
    Electricfield
    end
 }%
  \end@OpenObj%
  \ignorespaces}

\define@key[psset]{pst-electricfield}{Vmax}[10]{\def\psk@electricfieldVmax{#1 }}
\psset[pst-electricfield]{Vmax=10}
\define@key[psset]{pst-electricfield}{Vmin}[-10]{\def\psk@electricfieldVmin{#1 }}
\psset[pst-electricfield]{Vmin=-10}
\define@key[psset]{pst-electricfield}{stepV}[2]{\def\psk@electricfieldStepV{#1 }}
\psset[pst-electricfield]{stepV=2}
\define@key[psset]{pst-electricfield}{stepFactor}[0.67]{\def\psk@electricfieldStepFactor{#1 }}
\psset[pst-electricfield]{stepFactor=0.67}
%
\def\psEquipotential{\pst@object{psEquipotential}}
\def\psEquipotential@i(#1,#2)(#3,#4){%
  \pst@killglue%
  \addbefore@par{radius=1mm}%
  \begin@OpenObj%
  \pssetlength\pst@dimb\psk@radius
  \addto@pscode{%
   \tx@EFieldDict
   /QXYN [\psk@electricfieldQ] def
   /ChargeRadius \pst@number\pst@dimb def
   /N \psk@electricfieldN def
   /NbrePoints \psk@electricfieldpoints def
   /Vmax \psk@electricfieldVmax def
   /Vmin \psk@electricfieldVmin def
   /StepV \psk@electricfieldStepV def
   /StepFactor \psk@electricfieldStepFactor def
   /posArrow \psk@ElectricFieldposArrow def
   /arrowscale { \psk@arrowscale } def
   /xUnit \pst@number\psxunit def
   /yUnit \pst@number\psyunit def
   /LW \pst@number\pslinewidth def
   /xMin #1 def
   /xMax #3 def
   /yMin #2 def
   /yMax #4 def
   Equipotential
   end
  }%
\end@OpenObj%
  \ignorespaces}
\catcode`\@=\PstAtCode\relax
%% END
\endinput 
