# [pstricks] Re : Elektrostatic Field

Patrice Mégret Patrice.Megret at umons.ac.be
Tue Jan 19 11:55:20 CET 2010

Dear Manuel et al,

The solution based on implicit function can be extended for the equipotential to any number of point charges arbitrarily placed, but for the field lines thepoint  charges should be placed on a line if you generalize the line equation . If we can find the function f(x,y)=0 for the E field line with arbitrary geometry, then it should be possible to use implicit function.
Probably some care should be taken to avoid division by zero if the computation grid crosses then charge positions.

I tested your solution with two charges (Q1=1,Q2=+-0.5, located at z=+-1) and superpose with mine and it is perfect.  (see code below)
Concerning the computation time, your solution is very quick for two charges of same sign but quite slow with two opposite sign charges (I changed plotpoints to 200 in the parametric plot for opposite sign charges because with 2000 it is very slow).

So probably, for the general case, the field lines should be computed by your algorithm and the equipotential by implicit function (that allows also  to change the color with the sign, red and orange in the example below)

I have no idea how to put arrows on the field lines with my procedure.

Best regards,

Patrice

\documentclass{article}

\begin{document}

\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
%        /V q1 r1 div
%           q2 r2 div
%           q3 r3 div
%           q4 r4 div
%        Ex=-dV/dx
/Ex q1 xP xA sub mul r1 3 exp div
q2 xP xB sub mul r2 3 exp div
%        Ey=-dV/dy
/Ey q1 yP yA sub mul r1 3 exp div
q2 yP yB sub mul r2 3 exp div
/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{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 0.5 def
/xA 0 def     % leurs positions
/yA 1 def
/xB 0 def
/yB -1 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
}
}
\pscircle[fillstyle=solid](!xA yA){0.2}\pscircle[fillstyle=solid](!xB yB){0.2}
\begin{psclip}{\psframe[linestyle=none](-5.2,-5.2)(5.2,5.2)}
\multido{\r=0.4+0.2}{3}{%
\psplotImp[linestyle=dotted,linecolor=red](-6,-6)(6,6){%
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div add \r\space sub}}
\multido{\r=1.0+1.0}{3}{%
\psplotImp[linestyle=dashed,linecolor=red](-6,-6)(6,6){%
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div add \r\space sub}}
\multido{\r=0.2+0.4}{5}{%
\psplotImp[linestyle=solid,linecolor=blue](-6,-6)(6,6){%
y 1 sub x 2 exp y 1 sub 2 exp add sqrt div y 1 add x 2 exp y 1 add 2 exp add sqrt div 0.5 mul add \r\space add}}
\multido{\r=-0.2+-0.4}{5}{%
\psplotImp[linestyle=solid,linecolor=blue](-6,-6)(6,6){%
y 1 sub x 2 exp y 1 sub 2 exp add sqrt div y 1 add x 2 exp y 1 add 2 exp add sqrt div 0.5 mul add \r\space add}}
\psdots(0,1)(0,-1)
\end{psclip}
\psaxes{->}(0,0)(-5.5,-5.5)(5.5,5.5)[$y$,-90][$z$,0]
\end{pspicture*}
\end{center}

\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 -0.5 def
/xA 0 def     % leurs positions
/yA 1 def
/xB 0 def
/yB -1 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=200]{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=200]{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}
%\psgrid
\begin{psclip}{\psframe[linestyle=none](-5.2,-5.2)(5.2,5.2)}
\multido{\r=0.4+0.2}{3}{%
\psplotImp[linestyle=dashed,linecolor=red](-6,-6)(6,6){%
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div sub \r\space sub}}
\multido{\r=0.04+0.04}{3}{%
\psplotImp[linestyle=dashed,linecolor=red](-8,-8)(8,8){%
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div sub \r\space sub}}
\multido{\r=-0.4+-0.2}{3}{%
\psplotImp[linestyle=dashed,linecolor=orange](-6,-6)(6,6){
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div sub \r\space sub}}
\multido{\r=-0.04+-0.04}{3}{%
\psplotImp[linestyle=dashed,linecolor=orange](-6,-6)(6,6){
x 2 exp y 1 sub 2 exp add sqrt 1 exch div x 2 exp y 1 add 2 exp add sqrt 0.5 exch div sub \r\space sub}}
\multido{\r=0.0+0.08}{10}{%
\psplotImp[linestyle=solid,linecolor=blue](-6,-6)(6,6){
y 1 sub x 2 exp y 1 sub 2 exp add sqrt div y 1 add x 2 exp y 1 add 2 exp add sqrt div 0.5 mul sub \r\space add}}
\multido{\r=-0.02+-0.06}{10}{%
\psplotImp[linestyle=solid,linecolor=blue](-6,-6)(6,6){
y 1 sub x 2 exp y 1 sub 2 exp add sqrt div y 1 add x 2 exp y 1 add 2 exp add sqrt div 0.5 mul sub \r\space add}}
\psdots(0,1)(0,-1)
\end{psclip}
\psaxes{->}(0,0)(-5.5,-5.5)(5.5,5.5)[$y$,-90][$z$,0]
\end{pspicture*}
\end{center}

\end{document}

De : pstricks-bounces at tug.org [mailto:pstricks-bounces at tug.org] De la part de mluque5130 at aol.com
Envoyé : lundi 18 janvier 2010 20:11
À : pstricks at tug.org
Objet : [pstricks] Re : Elektrostatic Field

The solution of Patrice is very good! I think Patrick has won the challenge of tracing field lines and equipotential ... for now ...
How to add arrows to the field lines?

Thanks to Herbert for the improved code.

Best regards,

Manuel

________________________________
Important notification: In the context of the creation of the University of Mons, FPMs email address policy is changing from '@fpms.ac.be' to '@umons.ac.be' (or @student.fpms.ac.be to @student.umons.ac.be), please update your contact list accordingly.

Note importante: Dans le cadre de la création de l'Université de Mons, la stratégie d'adresse de courrier électronique de la FPMs change de '@fpms.ac.be' à '@umons.ac.be' (ou @student.fpms.ac.be to @student.umons.ac.be), merci de mettre à jour votre liste d'adresses en conséquence.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20100119/2b0f74e8/attachment-0001.html>