summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-magneticfield
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-05-17 16:10:33 +0000
committerKarl Berry <karl@freefriends.org>2010-05-17 16:10:33 +0000
commit0fbe3bb2fe6072a4909daddb5cfb7304dce43981 (patch)
tree4a016a5a590831850d8aab9aebf0bf87cc6c3536 /Master/texmf-dist/tex/generic/pst-magneticfield
parent7fe9b95e32b8a9ec7f8fb1465ef797c3fe282301 (diff)
new pstricks package pst-magneticfield (16may10)
git-svn-id: svn://tug.org/texlive/trunk@18313 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pst-magneticfield')
-rw-r--r--Master/texmf-dist/tex/generic/pst-magneticfield/pst-magneticfield.tex379
1 files changed, 379 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/pst-magneticfield/pst-magneticfield.tex b/Master/texmf-dist/tex/generic/pst-magneticfield/pst-magneticfield.tex
new file mode 100644
index 00000000000..8d8e583baba
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/pst-magneticfield/pst-magneticfield.tex
@@ -0,0 +1,379 @@
+%% Package `pst-magneticfield.tex'
+%%
+%% Manuel Luque
+%% Jürgen Gilg
+%% 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 magnetic field lines
+%% It uses the method from Heun
+%%
+\csname PSTMagneticFieldLoaded\endcsname
+\let\PSTMagneticFieldLoaded\endinput
+%
+% Requires some packages
+\ifx\PSTricksLoaded\endinput\else \input pstricks \fi
+\ifx\PSTthreeDLoaded\endinput\else\input pst-3d \fi
+\ifx\MultidoLoaded\endinput\else \input multido.tex\fi
+\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey \fi
+%
+\def\fileversion{1.10}
+\def\filedate{2010/05/16}
+\message{`pst-magneticfield' v\fileversion, \filedate\space (ml,jg,hv)}
+%
+\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
+%
+\SpecialCoor
+\pst@addfams{pst-magneticfield}
+% the first three parameter cannot be read with \pst@getint, because \pstFP.. do not like
+% the values ... used in \psmagenticfieldThreeD
+\define@key[psset]{pst-magneticfield}{R}[1]{\def\psk@magneticfieldR{#1}}% rayon d'une spire
+\define@key[psset]{pst-magneticfield}{N}[6]{\def\psk@magneticfieldN{#1}}% nombre de spires
+\define@key[psset]{pst-magneticfield}{L}[4]{\def\psk@magneticfieldL{#1}}% Longueur de la bobine
+\define@key[psset]{pst-magneticfield}{nL}[8]{\pst@getint{#1}\psk@magneticfieldNL}% nombre de lignes de champ
+\define@key[psset]{pst-magneticfield}{numSpires}[]{\def\psk@magneticfieldChoixSpires{#1}}% choix individuel des spires
+\psset[pst-magneticfield]{numSpires=}% toutes les spires par défaut
+\define@key[psset]{pst-magneticfield}{pointsB}[500]{\pst@getint{#1}\psk@magneticfieldB}
+\define@key[psset]{pst-magneticfield}{pointsS}[1000]{\pst@getint{#1}\psk@magneticfieldS}% nombre de points autour de chaque spire
+\define@key[psset]{pst-magneticfield}{PasB}[0.02]{\pst@checknum{#1}\psk@magneticfieldPasB}% incrément du tracé autour de la bobine
+\define@key[psset]{pst-magneticfield}{PasS}[0.00275]{\pst@checknum{#1}\psk@magneticfieldPasS}% incrément du tracé autour de chaque spire
+\define@key[psset]{pst-magneticfield}{nS}[1]{\pst@getint{#1}\psk@magneticfieldNS}% nombre de lignes autour de chaque spire
+\define@key[psset]{pst-magneticfield}{styleSpire}[styleSpire]{\def\psk@styleSpire{#1}}
+\define@key[psset]{pst-magneticfield}{styleCourant}[sensCourant]{\def\psk@styleCourant{#1}}
+%
+\newpsstyle{styleSpire}{linecap=1,linecolor=red,linewidth=2\pslinewidth}
+\newpsstyle{sensCourant}{linecolor=red,linewidth=2\pslinewidth,arrowinset=0.1}
+\newpsstyle{grille}{subgriddiv=0,gridcolor=lightgray,griddots=10}
+\newpsstyle{cadre}{linecolor=green!20}
+%
+\define@boolkey[psset]{pst-magneticfield}[Pst@]{drawSelf}[true]{}
+\define@boolkey[psset]{pst-magneticfield}[Pst@]{AntiHelmholtz}[true]{}
+%
+\psset[pst-magneticfield]{R=1,L=4,N=6,pointsB=500,pointsS=1000,
+ PasB=0.02,PasS=0.00275,nS=1,nL=8,drawSelf,styleSpire=styleSpire,
+ styleCourant=sensCourant,AntiHelmholtz=false}
+%
+\def\psmagneticfield{\pst@object{psmagneticfield}}
+\def\psmagneticfield@i{%
+ \pst@killglue%
+% \ifPst@AntiHelmholtz\addto@par{N=2}\fi
+ \begin@SpecialObj%
+ \pst@Verb{% make it global
+ /NombreSpires \psk@magneticfieldN\space def
+ /Radius \psk@magneticfieldR\space def
+ /nombreLignes \psk@magneticfieldNL\space def
+ /TableauSpires [\psk@magneticfieldChoixSpires] def
+ \ifPst@AntiHelmholtz
+ TableauSpires length 0 eq {/TS [1 2] def}
+ {/TS TableauSpires def } ifelse
+ \else
+ TableauSpires length 0 eq {/TS [1 1 NombreSpires {} for] def}
+ {/TS TableauSpires def } ifelse
+ \fi
+ /StepLines Radius nombreLignes 1 add div def
+ NombreSpires 1 eq
+ { /Longueur 0 def
+ /inter 0 def }
+ { /Longueur \psk@magneticfieldL\space def
+ /inter Longueur NombreSpires 1 sub div def } ifelse % intervalle entre 2 spires
+ /NbrePointsB \psk@magneticfieldB\space def
+ /NbrePointsS \psk@magneticfieldS\space def
+ \ifPst@AntiHelmholtz
+ /inter Radius def
+ /yA Radius 2 div def
+ \else
+ /yA Longueur 2 div def
+ \fi
+ /PasB \psk@magneticfieldPasB\space def
+ /PasS \psk@magneticfieldPasS\space def
+ /nS \psk@magneticfieldNS\space def
+ }%
+ \addto@pscode{
+ /fleche {
+ gsave
+ x2 y2 moveto
+ y2 y1 sub x2 x1 sub atan rotate % 1 1 scale
+ -1 CLW mul 2 CLW mul rlineto
+ 7 CLW mul -2 CLW mul rlineto
+ -7 CLW mul -2 CLW mul rlineto
+ closepath
+ fill
+ grestore
+ } def
+ /Calcul_B_Spires {
+ /Bx 0 def
+ /By 0 def
+ 1 1 NombreSpires { % on calcule le champ resultant de toutes les spires
+ /iS ED % numero de la spire
+ /yi yA iS 1 sub inter mul sub def % position de la spire
+ /Bx0 {
+ /arz {1 Radius xP add dup mul yP yi add dup mul add sqrt div} def
+ yP yi add xP div arz mul
+ EllipticK neg
+ Radius dup mul xP dup mul add yP yi add dup mul add
+ Radius xP sub dup mul yP yi add dup mul add div
+ EllipticE mul
+ add
+ mul
+ } def
+ /By0 {
+ /arz {1 Radius xP add dup mul yP yi add dup mul add sqrt div} def
+ arz
+ EllipticK
+ Radius dup mul xP dup mul sub yP yi add dup mul sub
+ Radius xP sub dup mul yP yi add dup mul add div
+ EllipticE mul
+ add
+ mul
+ } def
+ \ifPst@AntiHelmholtz
+ iS 2 eq {/Bx0 Bx0 neg def /By0 By0 neg def} if
+ \fi
+ /Bx Bx Bx0 add def
+ /By By By0 add def
+ } for
+ } def
+ /EllipticKE{
+ /K {2 Radius xP mul sqrt mul arz mul} def
+ /m1 {1 K dup mul sub} def
+ /m2 {m1 dup mul} def
+ /m3 {m2 m1 mul} def
+ /m4 {m2 dup mul} def
+ /m_1 {1 m1 div} def
+ /EllipticK {
+ 0.5
+ 0.12498593597 m1 mul add
+ 0.06880248576 m2 mul add
+ 0.03328355376 m3 mul add
+ 0.00441787012 m4 mul add
+ m_1 ln mul
+ 1.38629436112 add
+ 0.09666344259 m1 mul add
+ 0.03590092383 m2 mul add
+ 0.03742563713 m3 mul add
+ 0.01451196212 m4 mul add
+ } def
+ /EllipticE {
+ 0.24998368310 m1 mul
+ 0.09200180037 m2 mul add
+ 0.04069697526 m3 mul add
+ 0.00526449639 m4 mul add
+ m_1 ln mul
+ 1 add
+ 0.44325141463 m1 mul add
+ 0.062606012206 m2 mul add
+ 0.04757383546 m3 mul add
+ 0.01736506451 m4 mul add
+ } def
+ Calcul_B_Spires
+% au point Pi
+ /xPi xP def
+ /yPi yP def
+ /NormeB Bx dup mul By dup mul add sqrt def
+ /dX Bx NormeB div Pas mul def
+ /dXi dX def
+ /dY By NormeB div Pas mul def
+ /dYi dY def
+ /xCi xPi dX add def
+ /yCi yPi dY add def
+ /xP xCi def
+ /yP yCi def
+ Calcul_B_Spires
+% au point C
+ /NormeB Bx dup mul By dup mul add sqrt def
+ /dX Bx NormeB div Pas mul def
+ /dY By NormeB div Pas mul def
+ /yP yPi dY dYi add 2 div add def
+ } def
+%
+ 0 0 translate
+ /Lignes_Champ {
+ /Ligne_Champ [
+ NbrePoints {%
+ EllipticKE
+ [ xP yP \tx@ScreenCoor ]
+ trace 1 eq {By 0 lt Bx 0 lt and {exit} if} if
+ } repeat
+ ] def
+%
+ Ligne_Champ 0 get aload pop moveto % xP yP
+ 1 1 Ligne_Champ length 1 sub {
+ /iCompteur exch def
+ Ligne_Champ iCompteur get aload pop lineto
+ } for
+ stroke
+% les flèches (xP,yP)
+ Ligne_Champ dup length 1 sub 3 div cvi get aload pop /y1 exch def /x1 exch def
+ Ligne_Champ dup length 1 sub 3 div cvi 1 add get aload pop /y2 exch def /x2 exch def
+ nCount 0 eq {/yAxe1 y1 def /yAxe2 y2 def} if
+ fleche
+%
+ Ligne_Champ 0 get aload pop neg moveto % xP -yP
+ 1 1 Ligne_Champ length 1 sub {
+ /iCompteur ED
+ Ligne_Champ iCompteur get aload pop neg lineto
+ } for
+ stroke
+ trace 1 eq {
+% (xP,-yP)
+ Ligne_Champ dup length 1 sub 3 div cvi get aload pop /y2 exch neg def /x2 ED
+ Ligne_Champ dup length 1 sub 3 div cvi 1 add get aload pop /y1 exch neg def /x1 ED
+ fleche
+ } if
+ Ligne_Champ 0 get aload pop exch neg exch moveto % -xP yP
+ 1 1 Ligne_Champ length 1 sub {
+ /iCompteur ED
+ Ligne_Champ iCompteur get aload pop exch neg exch lineto
+ } for
+ stroke
+% (-xP,yP)
+ Ligne_Champ dup length 1 sub 3 div cvi get aload pop /y1 exch def /x1 exch neg def
+ Ligne_Champ dup length 1 sub 3 div cvi 1 add get aload pop /y2 exch def /x2 exch neg def
+ fleche
+ Ligne_Champ 0 get aload pop exch neg exch neg moveto % -xP -yP
+ 1 1 Ligne_Champ length 1 sub {
+ /iCompteur ED
+ Ligne_Champ iCompteur get aload pop exch neg exch neg lineto
+ } for
+ stroke
+ trace 1 eq {
+% (-xP,-yP)
+ Ligne_Champ dup length 1 sub 3 div cvi get aload pop /y2 exch neg def /x2 exch neg def
+ Ligne_Champ dup length 1 sub 3 div cvi 1 add get aload pop /y1 exch neg def /x1 exch neg def
+ fleche
+ } if
+ } def
+%
+% lignes de champ de l'ensemble de la bobine
+ /trace 1 def
+ /nCount 0 def
+% 0.1 Radius mul StepLines Radius mul 0.9 Radius mul {
+ StepLines StepLines Radius 1.5 StepLines mul sub {
+ /NbrePoints NbrePointsB def
+ /xStart ED
+ /yStart 0 def
+ /Pas PasB def
+ /xP xStart def
+ /yP yStart Pas sub def
+ Lignes_Champ
+ /nCount nCount 1 add def
+ } for
+ \ifPst@AntiHelmholtz\else
+ % l'axe orienté de la bobine
+ 0 -10 \tx@ScreenCoor moveto
+ 0 10 \tx@ScreenCoor lineto
+ stroke
+ /x1 0 def
+ /y1 yAxe1 def
+ /y2 yAxe2 def
+ /x2 0 def
+ fleche
+ %/x1 0 def
+ /y1 yAxe2 neg def
+ /y2 yAxe1 neg def
+ %/x2 0 def
+ fleche
+ \fi
+ % quelques lignes de champ autour de chaque spire
+ /trace 0 def
+ /increment 0.25 Radius mul def
+ \ifPst@AntiHelmholtz
+ /Pas PasS def
+ /NbrePoints NbrePointsS def
+ \fi
+ nS { % nS lignes
+ 0 1 TS length 1 sub {
+ /nTemp ED
+ /iS TS nTemp get def % numero de la spire en partant du haut
+ iS 0 eq { /iS 1 def } if % iS ne peut pas = 0
+ iS NombreSpires gt { /iS NombreSpires def } if % iS ne peut pas > nbre spires
+ /yi yA iS 1 sub inter mul sub def % position du centre de la spire
+ \ifPst@AntiHelmholtz\else
+ /NbrePoints NbrePointsS def
+ /Pas PasS def
+ \fi
+ /xStart Radius increment add def
+ /yStart yi def
+ /xP xStart def
+ /yP yStart Pas sub def
+ Lignes_Champ
+ } for
+ \ifPst@AntiHelmholtz /NbrePoints NbrePoints 750 add def \fi
+ /increment increment 0.2 Radius mul add def
+ } repeat
+ }%
+ \ifPst@drawSelf
+ \ifPst@AntiHelmholtz
+ \psline[style=\psk@styleSpire](!Radius neg Radius 2 div)(!Radius Radius 2 div)
+ \psline[style=\psk@styleCourant]{<-}(!-0.2 Radius 2 div)(!0.2 Radius 2 div)
+ \psline[style=\psk@styleSpire](!Radius neg Radius 2 div neg)(!Radius Radius 2 div neg)
+ \psline[style=\psk@styleCourant]{->}(!-0.2 Radius 2 div neg)(!0.2 Radius 2 div neg)
+ \else
+ \multido{\i=1+1}{\psk@magneticfieldN}{% numero de la spire
+ \pst@Verb{ /Yspire yA \i\space 1 sub inter mul sub def } % position de la spire
+ \psline[style=\psk@styleSpire](! Radius neg Yspire)(! Radius Yspire)
+ \psline[style=\psk@styleCourant]{->}(!-0.2 Yspire)(!0.2 Yspire)}
+ \fi
+ \fi%
+ \end@SpecialObj%
+ \ignorespaces}
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%\psmagneticfieldThreeD%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+\def\psmagneticfieldThreeD{\pst@object{psmagneticfieldThreeD}}
+\def\psmagneticfieldThreeD@i(#1,#2)(#3,#4){%
+% \ifPst@AntiHelmholtz\addto@par{N=2}\fi
+ \begingroup
+ \use@par
+ \ifPst@AntiHelmholtz
+ \pstFPdiv\yA{\psk@magneticfieldR}{2}
+ \ThreeDput{%
+ \begin{psclip}{\psframe(#1,#2)(#3,#4)}
+ \psframe*[style=cadre](#1,#2)(#3,#4)
+ \psgrid[style=grille](#1,#2)(#3,#4)
+ \psmagneticfield[drawSelf=false]%
+ \end{psclip}}
+ \ThreeDput[normal=0 1 0](0,\yA,0){%
+ \psarc[linecolor=red,linewidth=3\pslinewidth](0,0){\psk@magneticfieldR}{0}{180}
+ \psarc[linecolor=red,linewidth=3\pslinewidth]{<-}(0,0){\psk@magneticfieldR}{80}{90}
+ \psarc[linecolor=red,linewidth=1\pslinewidth,linestyle=dashed](0,0){\psk@magneticfieldR}{180}{360}}
+ \ThreeDput[normal=0 1 0](0,-\yA,0){%
+ \psarc[linecolor=red,linewidth=3\pslinewidth](0,0){\psk@magneticfieldR}{0}{180}
+ \psarc[linecolor=red,linewidth=3\pslinewidth]{->}(0,0){\psk@magneticfieldR}{80}{90}
+ \psarc[linecolor=red,linewidth=1\pslinewidth,linestyle=dashed](0,0){\psk@magneticfieldR}{180}{360}}
+ \else
+ \ifnum\psk@magneticfieldN=1
+ \def\MF@inter{0}
+ \def\yA{0}
+ \else
+ \pstFPsub\CalcIntermediaire{\psk@magneticfieldN}{1}
+ \pstFPdiv\MF@inter{\psk@magneticfieldL}{\CalcIntermediaire}
+ \pstFPdiv\yA{\psk@magneticfieldL}{2}
+ \fi
+ \ThreeDput{%
+ \begin{psclip}{\psframe(#1,#2)(#3,#4)}
+ \psframe*[style=cadre](#1,#2)(#3,#4)
+ \psgrid[style=grille](#1,#2)(#3,#4)
+ \psmagneticfield[drawSelf=false]%
+ \end{psclip}}
+ \multido{\iN=1+1,\iS=0+1}{\psk@magneticfieldN}{%
+ \pstFPmul\MF@calcA{\iS}{\MF@inter}
+ \pstFPsub\posSpire{\yA}{\MF@calcA}
+ \ThreeDput[normal=0 1 0](0,\posSpire,0){%
+ \psarc[linecolor=red,linewidth=3\pslinewidth](0,0){\psk@magneticfieldR}{0}{180}
+ \psarc[linecolor=red,linewidth=3\pslinewidth]{->}(0,0){\psk@magneticfieldR}{80}{90}
+ \psarc[linecolor=red,linewidth=1\pslinewidth,linestyle=dashed](0,0){\psk@magneticfieldR}{180}{360}}%
+ }%
+ \fi
+ \endgroup}
+%
+\catcode`\@=\PstAtCode\relax
+%
+%% END
+\endinput
+