如何使用 TikZ 绘制原电池?

如何使用 TikZ 绘制原电池?

使用 TikZ,我们可以创建一个原电池图形,就像这张图片(或更精美的图片;))一样吗?

在此处输入图片描述

我尝试过创建一个,但显然我不太擅长;(

    \begin{tikzpicture}
\draw (2,6)--(2,8)--(4,8)(4,7.5)rectangle(5.5,8.5) node[midway] {$R$} (5.5,8)--(7,8)(7.5,8)circle(0.5)node{A} (8,8)--(10,8)--(10,6);
\draw (1,6)--(1,1)--(2,1)(2,1)--(5,1)(6,6)--(6,1)--(5,1)(1,5)--(6,5);

\end{tikzpicture}

在此处输入图片描述

比如,我们如何才能制作出圆角?顺便说一句,在我的电化学教科书中,那不是电压表;而是电流表。

答案1

这是我有的一张旧图。这是 Daniell 电池,但它并不完全像你的例子。我添加了圆角(显然是在命令rounded corners中使用选项\draw),并更改了电极颜色。其余的都是我所拥有的,但我认为你可以轻松更改它。我使用mhchem化学包,你可能不需要它。

\documentclass[border=2mm]{standalone}
\usepackage   [version=4] {mhchem} % for the chemistry
\usepackage               {tikz}

\begin{document}
\begin{tikzpicture}[line join=round, line cap= round]
  % CELLS AND ELECTRODES
  \begin{scope}
    \draw[thick,fill=gray!50] (0.5,1) rectangle (1,5);    % Zn electrode
    \draw[thick,rounded corners] (0,4) |- (4,0) -- (4,4); % left cell
    \clip[rounded corners]       (0,4) |- (4,0) -- (4,4) -- cycle;
    \fill[gray,opacity=0.3]   (0,0)   rectangle (4,3);    % ZnSO4 solution
  \end{scope}
  \begin{scope}
    \draw[thick,fill=orange!50] (8,1) rectangle (8.5,5);  % Cu electrode
    \draw[thick,rounded corners] (5,4) |- (9,0) -- (9,4); % right cell
    \clip[rounded corners]       (5,4) |- (9,0) -- (9,4) -- cycle;
    \fill[blue, opacity=0.2]    (5,0) rectangle (9,3);    % CuSO4 solution
  \end{scope}
  % SALINE BRIDGE
  \draw[thick] (3,1)   --++ (0,2.5) arc (180:0:1.5) --++ (0,-2.5);
  \draw[thick] (3.5,1) --++ (0,2.5) arc (180:0:1)   --++ (0,-2.5);
  % WIRE AND VOLTMETER
  \draw[thick, rounded corners=0.5 cm] (0.75,5) |- (8.25,7) -- (8.25,5);
  \begin{scope}[shift={(4.5,7)}]
  \draw[thick,fill=white] (0,0) circle (0.5);
    \foreach\a in{30,60,...,150}
    {%
      \draw[blue,thin] (\a:0.35) -- (\a:0.45);
    }
  \fill[blue] (0,0) circle (1pt);
  \draw[blue,thick,-latex] (0,0) -- (60:0.4);
  \end{scope}
  % ELECTRONS
  \begin{scope}[shift={(1.5,6.25)}]
    \draw[red,thick,rounded corners=0.3 cm,->] (-0.5,-0.5) |- (0.5,0.5);
  \end{scope}
  % SIGNS
  \draw[red,thick] (-0.5,5.5) circle (0.25);
  \draw[red,thick] (9.5,5.5)  circle (0.25);
  \draw[red,thick] (-0.7,5.5) -- (-0.3,5.5);
  \draw[red,thick] (9.3,5.5)  -- (9.7,5.5);
  \draw[red,thick] (9.5,5.3)  -- (9.5,5.7);
  % LABELS
  \node at (4.5,8)    {Voltmeter};
  \node at (4.5,5.5)  {Saline bridge (\ce{KCl})};
  \node at (-0.5,5)   {Anode};
  \node at (-0.5,4.5) {(oxidation)};
  \node at (9.5,5)    {Cathode};
  \node at (9.5,4.5)  {(reduction)};
  \node[red] at (1.5,6.25) {\ce{e^-}};
  % CHEMISTRY
  \node at (2,-0.5) {\ce{ZnSO4}};
  \node at (7,-0.5) {\ce{CuSO4}};
  \node at (0.75,2) {\ce{Zn}};
  \node at (8.25,2) {\ce{Cu}};
  \node at (0.85,2) [right] {\small\ce{-> Zn^2+}};
  \node at (8.15,2) [left]  {\small\ce{Cu^2+ ->}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

以下是您可以实现的示例。您可以用来创建图形的大多数技巧都用在了电压表的这次尝试中。

在此处输入图片描述

以下是创建该功能的代码:

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

%% ------------------------------------------------------------
%%  A sort of one-stop-shop for controlling sizes and          
%%  positions of things.                                       
%% ------------------------------------------------------------
\def\aes{*0.75cm}
\def\radiusA{3\aes}
\def\radiusB{1.5\aes}
\def\aeoff{0.25\aes}

%% ------------------------------------------------------------
%%  Create some layers to facilitate coloring in the places    
%%  you want colored in.                                       
%% ------------------------------------------------------------
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture}
   
  %% I find naming things helps keep track what you're doing.
  %% otherwise this is entirely gratuitous.
  \coordinate (origin) at (0,0);
  \coordinate (start)  at ($(origin)+(3\aes,0)$);
  \coordinate (end)    at ($(origin)-(3\aes,0)$);

  %% the inner workings on the voltmeter               
  %% and creating two coordinates that will facilitate 
  %% in drawing the outer box                          
  \draw[fill=white]
        (start) -- ++ (0.25\aes,0\aes)               
                -- ++ (0\aes,2.75\aes)                coordinate (inrttop)
                -- ++ ( -0.25\aes*2-\radiusA*2,0pt)  
                -- ++ (0\aes,-2.75\aes)               coordinate (inltbot)
                -- (end)
                   arc(180:0:{\radiusA} and {\radiusB});
                ;

  %% create the outer top    right corner of the outer box
  %% create the outer bottom left  corner of the outer box
  \coordinate (outrttop) at ($(inrttop)+( \aeoff, \aeoff)$);
  \coordinate (outltbot) at ($(inltbot)+(-\aeoff,-\aeoff)$);

  %% create the gray box
  %% by specifying a `background` layer, I don't obliterate
  %% everything else I've already drawn.
  \begin{pgfonlayer}{background}
    \draw[fill=gray!20] (outrttop) rectangle (outltbot);
  \end{pgfonlayer}

  %% drawing the markings in the voltmeter 
  %% and singling out one in particular as the needle in red
  %% ------------------------------------------------------------
  %% I'm cheating here a bit.  Ideally the markings should       
  %% probably be drawn perpendicular to the tangent of the       
  %% ellipse.  That just seems like a lot of work.  And I        
  %% noticed that in figure you provided, it wasn't done that    
  %% way either.  So, perhaps not the worse cheat.               
  \foreach \mya in {40,70,90,100,110,140}
  {
    \coordinate (A\mya) at ($(origin)+(\mya:{\radiusA} and {\radiusB})$);
    \ifnum\mya=100\relax
      \draw[red] (A\mya) -- ++ ($(A\mya)!0.50!(origin)$);
    \else
      \draw (A\mya) -- ++ ($(A\mya)!0.85!(origin)$);
    \fi
    
  }

  %% the label for the voltmeter
  \node[anchor=south] at (origin) {Voltmeter};

\end{tikzpicture}

\end{document}

TikZ 手册非常详尽,但找到你想要的内容可能有点困难。近年来,手册的结构或多或少相似,章节标题也相似。因此,以下建议应该相当可靠,可以让你找到手册的适当部分。

我建议先阅读有关tikzlibraryfor 的内容calc。我所做的大部分工作将在本手册的这一部分中进行解释。

接下来,您需要了解我使用过的基本节点和路径构造函数:、、、、等。例如,如果您在 pdf 中搜索,\draw您可以相当轻松地阅读其中的大部分内容。要查找详细信息,请搜索和(前者将为您提供大部分必要的详细信息,只会告诉您它的简写形式)。coordinatenodefill\path . . . node\draw/tikz/draw\draw\draw

的使用--可以在line-to operation

的使用rectangle可以在rectangle operation

找到符号有点困难++。为此,请搜索Specifying Coordinates

其中还有一个部分Arc Operations将解释该语法的使用arc(<start angle>:<end angle>:<radius A> and <radius B>)

还有一整个部分帮助Using Layers您了解图层的含义以及您可以使用它们做什么。

相关内容