[pstricks] Re : Re : Re : Elektrostatic Field

Herbert Voss Herbert.Voss at FU-Berlin.DE
Mon Jan 18 14:52:29 CET 2010


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!

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

\documentclass{article}
\usepackage{pstricks-add}
\SpecialCoor
\def\FieldLinesFourElectricCharges{
  1 1 4 { /i ED xP i getX sub yP i getY sub Pyth } for
  4 array astore /Radius ED
  0 0
  1 1 4 { /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}
\begin{center}
\begin{pspicture*}(-5,-5)(5,5)
% les limites
\multido{\iB=1+1}{4}{%
  \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 [1 1 1 1] def
      /Xcoor [ -2.5  2.5 2.5 -2.5 ] def
      /Ycoor [ -2.5 -2.5 2.5  2.5 ] def
      /getX { 1 sub Xcoor exch get } def
      /getY { 1 sub Ycoor exch get } def
      /getQ { 1 sub Qcharge exch get } def
      /getR { 1 sub 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 } %
  }
}
\end{pspicture*}

\end{center}
\end{document}


More information about the PSTricks mailing list