[pstricks] Re : Re : Re : Elektrostatic Field

Herbert Voss Herbert.Voss at FU-Berlin.DE
Mon Jan 18 20:13:17 CET 2010


Am 18.01.2010 14:52, schrieb Herbert Voss:
> Am 18.01.2010 10:49, schrieb mluque5130 at aol.com:
>>
>>  It would be interesting to generalize to any number of electrical charges. Here's an example with four charges.  It's beautiful!
> 

> the same, a bit shorter. Can be modified to use n charges ...

here it is. I also tried the code from Patrice, which gives
a nice output, but it is really slow in compiling.

\documentclass{article}
\usepackage{pstricks-add}
\makeatletter
\let\ScreenCoor\tx at ScreenCoor
\makeatother
\def\FieldLinesFourElectricCharges{
  0 1 NoQ { /i ED xP i getX sub yP i getY sub Pyth } for
  NoQ 1 add array astore /Radius ED
  0 0
  0 1 NoQ { /i ED
    i getQ xP i getX sub mul i getR 3 exp Div add exch
    i getQ yP i getY sub mul i getR 3 exp Div add exch
  } for
  /Ex ED  /Ey ED
  /NormeE Ex Ey Pyth def
  /dX Ex NormeE div pasX mul def
  /dY Ey NormeE div pasX mul def
}
\begin{document}

\def\NoQ{5}
\def\Qcharge{-0.5 1 -1.5 1 1}
\def\Xcoor{0 -2.5  2.5 2.5 -2.5}
\def\Ycoor{0 -2.5 -2.5 2.5  2.5}

\begin{center}
\begin{pspicture*}(-5,-5)(5,5)
\multido{\iB=0+1}{\NoQ}{%
  \multido{\iA=0+15}{24}{% 24 lignes de champ
    \psparametricplot[plotpoints=2000]{xmin}{xmax}[{
      /xmin -5 def /xmax 5 def /ymin -5 def /ymax 5 def
      /pasX xmax xmin sub 200 div def % 0.05
      /Qcharge [\Qcharge] def
      /NoQ \NoQ\space 1 sub def
      /Xcoor [\Xcoor] def
      /Ycoor [\Ycoor] def
      /getX { Xcoor exch get } def
      /getY { Ycoor exch get } def
      /getQ { Qcharge exch get } def
      /getR { Radius exch get } def
      /xStart \iB\space getX  def
      /yStart \iB\space getY def
      /pasX  \iB\space getQ dup abs Div 0.05 mul def
      /xP xStart pasX \iA\space cos mul add def
      /yP yStart pasX \iA\space sin mul add def
 }]{\FieldLinesFourElectricCharges
   /xP xP dX add def /yP yP dY add def xP yP }%
  }
  \pscustom{
  \code{
    /Qcharge [\Qcharge] def
    /NoQ \NoQ\space 1 sub def
    /Xcoor [ \Xcoor ] def
    /Ycoor [ \Ycoor ] def
    /getX { Xcoor exch get } def
    /getY { Ycoor exch get } def
    /getQ { Qcharge exch get } def
    0 1 NoQ { /i exch def
      i getX i getY \ScreenCoor\space 10 i getQ abs mul 0 360 arc
        gsave i getQ 0 gt {1 0 0}{0 0 1}ifelse setrgbcolor fill grestore
stroke
    } for
  }}
}
\end{pspicture*}
\end{center}

\end{document}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xx.png
Type: image/png
Size: 38024 bytes
Desc: not available
URL: <http://tug.org/pipermail/pstricks/attachments/20100118/77dedf23/attachment-0001.png>


More information about the PSTricks mailing list