4

I have got an issue using the coil decoration in Tikz :

You may know that a charged particle spins around magnetic field lines (called cyclotron motion). However, near biased surface, the motion of the guiding center (i.e. the center of the loops) quit the linear motion along the B field line, and tend to follow the perpendicular-to-the-surface direction. This is what it looks like on Tikz :

enter image description here

With the following code :

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing,angles,quotes,decorations.pathmorphing}
\usepackage{newpxtext,newpxmath}
\usepackage[european,RPvoltages]{circuitikz}
\standaloneenv{circuitikz}

\begin{document}

    \begin{tikzpicture}[thick,scale=1, every node/.style={scale=1}]

    \def\ion#1#2{
        %\draw node[circle,shading=ball,minimum width=1cm,color = white] at (#1,#2) {$\textbf{+}$};
        \fill[white, ball color=blue!80!white] (#1, #2, 0) circle (0.5);
        \draw (#1,#2) node[color = white] {\Huge $\textbf{+}$}; 
    }
    
    \def\electron#1#2{
        %\draw node[circle,shading=ball,minimum width=1cm,color = white] at (#1,#2) {$\textbf{+}$};
        \fill[line width=0.0mm, white, ball color=red] (#1, #2, 0) circle (0.30);
        \draw (#1,#2) node[color = white] {\Large $\textbf{-}$}; 
    }
    
    % Electrodes
    \shade [left color = gray , right color = gray!25] (10,0) -- (11,0) -- (11,7) -- (10,7) -- cycle;
    \draw (10.5,3.5) node [rotate = -90] {Cathode, $V<0$ V};
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % plasma
    \shade [right color = blue!30 , left color = blue!10] (-0.5,0) -- (10,0) -- (10,7) -- (-0.5,7) -- cycle;
    
    \draw [thick] (-0.5,0) -- (11,0);
    \draw [thick] (-0.5,7) -- (11,7);
    \draw [very thick] (10,0) -- (10,7);
    
    \draw [ultra thick, ->,>=stealth] (0.5,5) -- (0.5,6.25);
    \draw (0.5,6) node [above left] {$x$};
    
    \draw [ultra thick, ->,>=stealth] (0.5,5) -- (1.75,5);
    \draw (1.5,5) node [below left] {$z$};
    \draw (0.5,5) node {$\bullet$};
    
    \draw [very thick,->,>=stealth] (0.5,5) --++ (45:1.4);
    \draw (0.5,5) ++ (45:1.4) node [above right] {$\vec{B}=B~\vec{b}$};
    \draw [very thick] (0.5,5.5) arc(90:45:0.5);
    \draw (0.5,5) ++ (70:0.75) node [] {$\psi$};
    
    \draw [dashed, very thick, red!40!blue] (0,0) -- (3,3) to[out = 45, in = -170] (7,5) -- (10,5);
    
    
    \draw [dashed, white!10!black, ultra thick](3,0) -- (3,7);
    \draw [dashed, white!10!black, ultra thick](7,0) -- (7,7);
    
    
    \draw (1.5,0) node [below, text width = 3cm,align = center]  {Prégaine \\ collisionnelle $\sim\lambda_i$};
    \draw (5,0) node [below, text width = 4cm,align = center]  {Prégaine \\ magnétique $\sim\rho_\text{ci}$};
    \draw (8.5,0) node [below, text width = 2.5cm,align = center]  {Gaine de Debye $\sim\lambda_\text{De}$};
    
    % THIS IS THE FRAGMENT TO DRAW THE BLUE COIL !!!!
    \draw [very thick, blue!50!white,->,>=stealth,decorate,decoration={coil,amplitude=10mm,segment length=10mm,post length=1mm}]
    (0,0) -- (3,3) to[out = 45, in = -170] (7,5) -- (10,5);
    % THIS was THE FRAGMENT TO DRAW THE BLUE COIL !!!!

    \draw [ultra thick,->,>=stealth,blue] (1,1) --++ (45:1);
    \draw (1,1) ++ (45:1) node [above left,blue] {$\vec{v}_i$};
    \ion{1}{1};
    
    
    \draw [ultra thick,->,>=stealth,blue] (3,3) --++ (45:1.4);
    \draw (3,3) ++ (45:1.4) node [below right,blue] {$\vec{v}_{i\parallel}=c_s~\vec{b}$};
    \ion{3}{3};
    
    \draw [ultra thick,->,>=stealth,blue] (7,5) --++ (0:1.4);
    \draw (7,5) ++ (0:1.4) node [below,blue] {$\vec{v}_{iz}=c_s~\vec{e}_z$};
    \ion{7}{5};
    
    \draw [very thick, red!80!white,->,>=stealth,decorate,decoration={coil,amplitude=1.4mm,segment length=2mm,post length=1mm}]
    (0,2.75) -- (4.25,7);
    \electron{0}{2.75};
    
    \draw [very thick, red!80!white,->,>=stealth,decorate,decoration={coil,amplitude=1.4mm,segment length=2mm,post length=1mm}]
    (5,0.5) -- (8,3.5);
    \draw [very thick , dotted , red!80!white] (8,3.5) -- ++(45:0.25);
    \electron{5}{0.5};
    
    
    \end{tikzpicture}
\end{document}

The problem is, that the coil must be perpendicular to the B direction, and not the guiding center path (the code relative to the coil drawing stands between both comments % THIS IS THE FRAGMENT TO DRAW THE BLUE COIL !!!!).

Therefore, my Tikz question : Is there a way to oblige the coil to keep the same inclination (i.e. perpendicular to B), but to also follow the purple dashed line ?

I want this (sorry for the bad quality) : enter image description here

Thanks in advance for your help!

7
  • I didn't quite understand, can you add a freehand drawing that shows the result you want to achieve? In any case, your drawing is already very beautiful.
    – AndréC
    Aug 17 '20 at 11:01
  • Thanks @AndréC, I have edited the post with hand made drawing... I hope it's clear enough :)
    – John
    Aug 17 '20 at 11:34
  • @hpekristiansen, I tried your proposition, but the result is not quite a "coil" able to give this kind of 3D rendering.
    – John
    Aug 17 '20 at 11:41
  • You need to play with the numbers and make it follow a path. This is a coil much like the decoration: \draw[very thick, red!50!white, domain={0:10}, smooth, variable=\t, samples=100] plot ( {0.3*\t+0.4*sin(\t* pi r)}, {1.0*cos(\t* pi r)} ); Aug 17 '20 at 11:45
  • 1
    First step is to make the purple path parametric(plot as function of \t) as well, and then add the coil. With the extra complication that the coil needs slope. I do not have time today, but if no one else answers, I will look at it tomorrow. Aug 17 '20 at 12:27
3

First a version that does not work:

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw [very thick, orange] (0,0) -- (3,3) to[out = 45, in = -180] (7,5) -- (10,5);
\draw [very thick, blue!50, decorate, decoration={coil,amplitude=10mm,segment length=10mm, transform={shift only, rotate=45}}] (0,0) -- (3,3) to[out = 45, in = -180] (7,5) -- (10,5);
\end{tikzpicture}
\end{document}

Path with strange coil

The transform={shift only, rotate=45} does not work well with the coil path morphing.


I make the path parametric - I chose to join the two straight sections by a parabola, and hope it is ok. Then I draw a parametric rotated coil added to this path:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({3*\t}, {3*\t});
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({4*\t+3},{-2*(\t-1)^2+5});
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({3*\t+7}, {5});
    %
    \draw[very thick, red!50, domain={0:10}, smooth, variable=\t, samples=100] plot ( {(0.3*\t+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {0.3*\t+cos((\t*pi-pi/2) r)} );
    \draw[very thick, red!50, domain={0:10}, smooth, variable=\t, samples=100] plot ( {(0.4*\t+3+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {-2*(0.1*\t-1)^2+5+cos((\t*pi-pi/2) r)} );
    \draw[very thick, red!50, domain={0:5}, smooth, variable=\t, samples=100] plot ( {(0.5*\t+7+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {5+cos((\t*pi-pi/2) r)} );
\end{tikzpicture}
\end{document}

Path with slanted coil

Things that could be better:

  • Because of the way I slant the coil, it does not start at the start point of the path.
  • Both the path and the coil are drawn in three section. It would be better to define a function and draw them both in one go. That way there would be not joins and the smooth would work across the whole path. I do not know how to do that.
  • Because of the three sections, I am forced to choose how many integer number of loops to add on each section. This makes the loops look more spaced on the first distance of the parabola. Maybe adjustments could be made to the path, if the exact path is not critical, so that the sections has integer ratio lengths.

Edit:

I realized, that the starting point is off not because of the slant, but because I start the loop a half cycle before - here is a corrected version:

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({3*\t}, {3*\t});
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({4*\t+3},{-2*(\t-1)^2+5});
    \draw [very thick, green!50, domain={0:1}, smooth, variable=\t, samples=100] plot ({3*\t+7}, {5});
    %
    \draw[very thick, blue, domain={0:10}, smooth, variable=\t, samples=100] plot ( {(0.3*\t+sqrt(18)/7+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {0.3*\t+cos((\t*pi-pi/2) r)} );
    \draw[very thick, blue, domain={0:10}, smooth, variable=\t, samples=100] plot ( {(0.4*\t+sqrt(18)/7+3+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {-2*(0.1*\t-1)^2+5+cos((\t*pi-pi/2) r)} );
    \draw[very thick, blue, domain={0:3}, smooth, variable=\t, samples=100] plot ( {(0.6*\t+sqrt(18)/7+7+0.8*sin((\t*pi-pi/2) r)*cos(45)-cos((\t*pi-pi/2) r)*sin(45)}, {5+cos((\t*pi-pi/2) r)} );
\end{tikzpicture}
\end{document}

Path and coil with corrected starting position

1
  • Thanks a lot for your help ! I tried several times, but never get to this nice result ! Your second code is just great. Thanks again.
    – John
    Aug 18 '20 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.