如何在 TikZ 中绘制两块板之间的电场线(可能是弯曲的)

如何在 TikZ 中绘制两块板之间的电场线(可能是弯曲的)

如何在 Ti 中绘制这些图形Z?

在此处输入图片描述

前两个图形我画出来了,但是箭头画得不太好:

\documentclass[tikz,border=3mm]{standalone} 
\begin{document} 
\begin{tikzpicture}
\foreach \i in {-3,...,3} 
    \draw[->] (\i,0)--(\i,-1.1); % Figure A
   %\draw[-<] (\i,0)--(\i,-1.1);   Figure B
\draw (-3,-1)--(-3,-2.2);
\draw (-2,-1)--(-2,-2.4);
\draw (-1,-1)--(-1,-2.6);
\draw (0,-1)--(0,-2.7);
\draw (3,-1)--(3,-2.2);
\draw (2,-1)--(2,-2.4);
\draw (1,-1)--(1,-2.6);
% It is ugly and time-consuming, right? but I can't find a better one
\draw[line width=3pt,red] (-3.5,0)--(3.5,0);
\draw (0,0) node[above] {$+$};
\draw[line width=3pt,blue] (-3.5,-2) to[out=-20,in=-160] (3.5,-2);
\draw (0,-2.7) node[below] {$-$};
\end{tikzpicture} 
\end{document}

在此处输入图片描述

由于我绘制直箭头的方式不是最佳的,所以我无法用它来绘制最后两个图中的弯曲箭头。

你能告诉我一个更好的方法吗?提前谢谢您。

答案1

这是一种替代方法,但与 marmot 的出色解决方案非常相似(仅比后者快几分钟)。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
% Library for middle arrowheads
\usetikzlibrary{decorations.markings}

    % Style the vertical lines (this form is necessary for the middle arrowhead)
    \begin{scope}[semithick,decoration={
        markings,
        mark=at position 0.4 with {\arrow{>}}}
    ]
    % Loop through and draw each vertical line
    \foreach \xRed in {-3,...,3}
        % Spread the bottom points horizontally
        \pgfmathsetmacro\xBlue{\xRed*1.1}
        % Red line is straight, but could put arbitrary function here
        \pgfmathsetmacro\yRed{0}
        % Blue line is curved, quadratic eqn
        \pgfmathsetmacro\yBlue{0.06*\xBlue*\xBlue-2.7}
        % Calculate angle of lines touching blue line
        \pgfmathsetmacro\angle{6.6667*\xRed+90}
        % Draw a line
        \draw[postaction={decorate}] (\xRed,\yRed) to[out=-90,in=\angle] (\xBlue,\yBlue);
    \end{scope}

    % Red line, could put arbitrary function here
    \draw[domain=-3.5:3.5,smooth,variable=\x,line width=3pt,red] plot ({\x},{0});
    % + sign
    \draw (0,0) node[above] {\(+\)};

    % Blue line, quadratic eqn
    \draw[domain=-3.5:3.5,smooth,variable=\x,line width=3pt,blue] plot ({\x},{0.06*\x*\x-2.7});
    % - sign
    \draw (0,-2.7) node[below] {\(-\)};

\end{tikzpicture}
\end{document}

最后结果

答案2

欢迎来到 TeX.SE!在这里decoration.markings可以\foreach帮到你很多。中间的箭头(基本上)来自这里。 和decorations.markings还用于沿蓝色曲线设置标记。它们用于定义箭头的起点。 用于将to[out=...,int=...]路径弯曲成CD

\documentclass[tikz,border=3mm]{standalone} 
\usetikzlibrary{decorations.markings,arrows.meta}
\tikzset{->-/.style={postaction={decorate,decoration={
  markings,
  mark=at position #1 with {\arrow[arsty]{>}}}}},
  -<-/.style={postaction={decorate,decoration={
  markings,
  mark=at position #1 with {\arrow[arsty]{<}}}}},
  insert target/.style args={#1|#2}{postaction={decorate,decoration={
  markings,
  mark=at position #1 with {\coordinate (target-#2);}}}}
  }
\begin{document} 
\begin{tikzpicture}[arsty/.style={},>=Latex,font=\sffamily]
 \begin{scope}[local bounding box=A]
  \draw[line width=3pt,red,
  %insert target/.list={1/12|Atop-1,3/12|Atop-2,5/12|Atop-3,7/12|Atop-4,9/12|Atop-5,11/12|Atop-6}
  ] (-3.5,0)--(3.5,0);
  \draw (0,0) node[above] {$+$};
  \draw[line width=3pt,blue,
  insert target/.list={1/12|Abot-1,3/12|Abot-2,5/12|Abot-3,7/12|Abot-4,9/12|Abot-5,11/12|Abot-6}] (-3.5,-2) to[out=-20,in=-160] (3.5,-2);
  \foreach \X in {1,...,6}
  {\draw[-<-=0.5] (target-Abot-\X) -- (0,0-|target-Abot-\X);}
  \draw (0,-2.7) node[below] {$-$};
 \end{scope}
 \node[anchor=south] at (A.north) {A};
 % 
 \begin{scope}[local bounding box=B,xshift=8cm]
  \draw[line width=3pt,red,
  %insert target/.list={1/12|Btop-1,3/12|Btop-2,5/12|Btop-3,7/12|Btop-4,9/12|Btop-5,11/12|Btop-6}
  ] (-3.5,0)--(3.5,0);
  \draw (0,0) node[above] {$+$};
  \draw[line width=3pt,blue,
  insert target/.list={1/12|Bbot-1,3/12|Bbot-2,5/12|Bbot-3,7/12|Bbot-4,9/12|Bbot-5,11/12|Bbot-6}] (-3.5,-2) to[out=-20,in=-160] (3.5,-2);
  \foreach \X in {1,...,6}
  {\draw[->-=0.5] (target-Bbot-\X) -- (0,0-|target-Bbot-\X);}
  \draw (0,-2.7) node[below] {$-$};
 \end{scope} 
 \node[anchor=south] at (B.north) {B};
 %
 \begin{scope}[local bounding box=C,yshift=-6cm]
  \draw[line width=3pt,red,
  %insert target/.list={1/12|Ctop-1,3/12|Ctop-2,5/12|Ctop-3,7/12|Ctop-4,9/12|Ctop-5,11/12|Ctop-6}
  ] (-3.5,0)--(3.5,0);
  \draw (0,0) node[above] {$+$};
  \draw[line width=3pt,blue,
  insert target/.list={1/12|Cbot-1,3/12|Cbot-2,5/12|Cbot-3,7/12|Cbot-4,9/12|Cbot-5,11/12|Cbot-6}] 
  (-3.5,-2) to[out=-20,in=-160] (3.5,-2);
  \foreach \X in {1,...,6}
  {\draw[-<-=0.5] (target-Cbot-\X) to[out=69+6*\X,in=-90] 
  ([xshift={(3.5-\X)*1.3mm}]target-Cbot-\X |-0,0);
  }
  \draw (0,-2.7) node[below] {$-$};
 \end{scope}
 \node[anchor=south] at (C.north) {C};
 % 
 \begin{scope}[local bounding box=D,xshift=8cm,yshift=-6cm]
  \draw[line width=3pt,red,
  insert target/.list={1/12|Dtop-1,3/12|Dtop-2,5/12|Dtop-3,7/12|Dtop-4,9/12|Dtop-5,11/12|Dtop-6}] (-3.5,0)--(3.5,0);
  \draw (0,0) node[above] {$+$};
  \draw[line width=3pt,blue,
  insert target/.list={1/12|Dbot-1,3/12|Dbot-2,5/12|Dbot-3,7/12|Dbot-4,9/12|Dbot-5,11/12|Dbot-6}] (-3.5,-2) to[out=-20,in=-160] (3.5,-2);
  \foreach \X in {1,...,6}
  {\draw[->-=0.5] (target-Dbot-\X) to[out=69+6*\X,in=-90] 
  ([xshift={(3.5-\X)*1.3mm}]target-Dbot-\X |-0,0);
  }
  \draw (0,-2.7) node[below] {$-$};
 \end{scope} 
 \node[anchor=south] at (D.north) {D};
\end{tikzpicture} 
\end{document}

在此处输入图片描述

相关内容