[pstricks] Re : Re : Re : Elektrostatic Field

mluque5130 at aol.com mluque5130 at aol.com
Mon Jan 18 10:49:36 CET 2010


 It would be interesting to generalize to any number of electrical charges. Here's an example with four charges.  It's beautiful!

\documentclass{article}
\usepackage{pstricks,pst-plot}
\SpecialCoor
\def\FieldLinesFourElectricCharges{%
         /r1 xP xA sub dup mul yP yA sub dup mul add sqrt def
         /r2 xP xB sub dup mul yP yB sub dup mul add sqrt def
         /r3 xP xC sub dup mul yP yC sub dup mul add sqrt def
         /r4 xP xD sub dup mul yP yD sub dup mul add sqrt def
%        /V q1 r1 div
%           q2 r2 div
%           add
%           q3 r3 div
%           add
%           q4 r4 div
%           add def
%        Ex=-dV/dx
         /Ex q1 xP xA sub mul r1 3 exp div
             q2 xP xB sub mul r2 3 exp div
             add
             q3 xP xC sub mul r3 3 exp div
             add
             q4 xP xD sub mul r4 3 exp div
             add def
%        Ey=-dV/dy
         /Ey q1 yP yA sub mul r1 3 exp div
             q2 yP yB sub mul r2 3 exp div
             add
             q3 yP yC sub mul r3 3 exp div
             add
             q4 yP yD sub mul r4 3 exp div
             add def
         /NormeE Ex dup mul Ey dup mul add sqrt def
         /dX Ex NormeE div pasX mul def
         /dY Ey NormeE div pasX mul def
}
\begin{document}
\begin{center}
\begin{pspicture*}(-7,-7)(7,7)
% les limites
\pstVerb{/xmin -5 def /xmax 5 def /ymin -5 def /ymax 5 def}%
% le nombre de lignes de champ
%\pstVerb{/NL 24 def}% 15 degrés entre chaque ligne (24*15=360)
% le pas d'itération
\pstVerb{/pasX xmax xmin sub 200 div def}% 0.05
\pstVerb{/q1 1 def        % les charges
         /q2 1 def
         /q3 1 def
         /q4 1 def
         /xA -2.5 def     % leurs positions
         /yA -2.5 def
         /xB 2.5 def
         /yB -2.5 def
         /xC 2.5 def
         /yC 2.5 def
         /xD -2.5 def
         /yD 2.5 def
         }%
\multido{\iA=0+15}{24}{% 24 lignes de champ
\pstVerb{/xStart xA def
         /yStart yA def
         /pasX q1 q1 abs div 0.05 mul def
         /xP xStart pasX \iA\space cos mul add def
         /yP yStart pasX \iA\space sin mul add def}%
\parametricplot[plotpoints=2000]{xmin}{xmax}{%
        \FieldLinesFourElectricCharges
        /xP xP dX add def
        /yP yP dY add  def
         xP yP
}
\pstVerb{/xStart xB def
         /yStart yB def
         /pasX q2 q2 abs div 0.05 mul def
         /xP xStart pasX \iA\space cos mul add def
         /yP yStart pasX \iA\space sin mul add def}%
\parametricplot[plotpoints=2000]{xmin}{xmax}{%
        \FieldLinesFourElectricCharges
        /xP xP dX add def
        /yP yP dY add  def
         xP yP
}
\pstVerb{/xStart xC def
         /yStart yC def
         /pasX q3 q3 abs div 0.05 mul def
         /xP xStart pasX \iA\space cos mul add def
         /yP yStart pasX \iA\space sin mul add def}%
\parametricplot[plotpoints=2000]{xmin}{xmax}{%
        \FieldLinesFourElectricCharges
        /xP xP dX add def
        /yP yP dY add  def
         xP yP
}
\pstVerb{/xStart xD def
         /yStart yD def
         /pasX q4 q4 abs div 0.05 mul def
         /xP xStart pasX \iA\space cos mul add def
         /yP yStart pasX \iA\space sin mul add def}%
\parametricplot[plotpoints=2000]{xmin}{xmax}{%
       \FieldLinesFourElectricCharges
        /xP xP dX add def
        /yP yP dY add  def
         xP yP
}
}
\pscircle[fillstyle=solid](!xA yA){0.2}\pscircle[fillstyle=solid](!xB yB){0.2}
\pscircle[fillstyle=solid](!xC yC){0.2}\pscircle[fillstyle=solid](!xD yD){0.2}
\end{pspicture*}
\end{center}
\end{document}



 Regards,

Manuel L.


 

 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20100118/294746c0/attachment.html>


More information about the PSTricks mailing list