没有使用 circuitikz 绘制欧姆表或万用表

没有使用 circuitikz 绘制欧姆表或万用表

虽然我使用的是 circuitikz,但我无法在简单的电路中绘制欧姆表。如果我用电压表或电流表代替欧姆表,它可以正常工作,否则则不行。另外,万用表有符号吗?

我的电路是

\begin{circuitikz}[american] 
\draw
(0,0) to[battery] (0,4)
(0,4) to[short, o-o] (2,4) 
(2,0) to[short,o-o] (0,0)
(3,4) to[R, o-o] (3,0)
(3,4) -- (4,4) 
   to[ohmmeter] (4,0)
(4,0) to[short,o-o] (3,0)
\end{circuitikz}

答案1

ohmmeter虽然它在文档中,但似乎没有定义。但是,由于除了文本字母外ohmmeter与 相同voltmeter,因此您可以按如下方式定义符号。

\documentclass[border={5pt}]{standalone}


\usepackage[american voltages,siunitx]{circuitikz}


\makeatletter
\def\pgf@circ@myvoltmeter@path#1{\pgf@circ@bipole@path{myvoltmeter}{#1}}
\tikzset{ohmmeter/.style = {\circuitikzbasekey, /tikz/to
                               path=\pgf@circ@myvoltmeter@path}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/voltmeter/height}}{myvoltmeter}
    {\ctikzvalof{bipoles/voltmeter/height}}{\ctikzvalof{bipoles/voltmeter/width}}
{
  \def\pgf@circ@temp{right}
  \ifx\tikz@res@label@pos\pgf@circ@temp
    \pgf@circ@res@step=-1.2\pgf@circ@res@up
  \else
    \def\pgf@circ@temp{below}
    \ifx\tikz@res@label@pos\pgf@circ@temp
      \pgf@circ@res@step=-1.2\pgf@circ@res@up
    \else
      \pgf@circ@res@step=1.2\pgf@circ@res@up
    \fi
  \fi

  \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}     
  \pgfpointorigin   \pgf@circ@res@other =  \pgf@x
  \advance \pgf@circ@res@other by -\pgf@circ@res@up
  \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
  \pgfusepath{draw}

  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}
                   \pgfstartlinewidth}

  \pgfscope
    \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
    \pgfusepath{draw}       
  \endpgfscope  

  \pgfsetlinewidth{\pgfstartlinewidth}
  \pgftransformrotate{90} % rotate the label
  \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
  \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{.8\pgf@circ@res@down}}
  \pgfusepath{draw}
  \pgfnode{circle}{center}{\textbf{\Large \si{\ohm}}}{}{}
  \pgfscope
     \pgftransformshift{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
     \pgftransformrotate{45}
     \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
  \endpgfscope

  \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
  \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
  \pgfusepath{draw}

  \pgfusepath{stroke}   
}
\makeatother




\begin{document}
\begin{circuitikz}[thick]
\draw
(0,4) to[battery] (0,0)
(0,4) to[short, o-o] (2,4) 
(2,0) to[short,o-o] (0,0)
(3,4) to[R, o-o] (3,0)
(3,4) -- (4,4)  to[ohmmeter](4,0);
\end{circuitikz}
\end{document}

结果是

在此处输入图片描述

答案2

只是为了好玩:

新欧姆表

\documentclass{standalone}
\usepackage{circuitikz}

\makeatletter
% ************************* analog meter **************************

\ctikzset{bipoles/meter/height/.initial=.80}
\ctikzset{bipoles/meter/width/.initial=.80}
\ctikzset{bipoles/meter/logo/.initial=$\Omega$}

\pgfcircdeclarebipole{}
  {\ctikzvalof{bipoles/meter/height}}
    {meter}
    {\ctikzvalof{bipoles/meter/height}}
    {\ctikzvalof{bipoles/meter/width}}
{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@up}{\northeast}
  \pgfextracty{\pgf@circ@res@down}{\southwest}
%
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfusepath{draw}
  \pgfpathcircle{\pgfpointorigin}{2\pgfstartlinewidth}
  \pgfusepath{fill}
  \pgfscope
    \pgfsetlinewidth{\pgfstartlinewidth}
        \pgftransformrotate{-\pgf@circ@direction}
    \pgfmoveto{\pgfpoint{0.7\pgf@circ@res@left}{0}}
    \pgflineto{\pgfpoint{0.9\pgf@circ@res@left}{0}}
    \pgfmoveto{\pgfpoint{0.566\pgf@circ@res@left}{0.411\pgf@circ@res@up}}
    \pgflineto{\pgfpoint{0.728\pgf@circ@res@left}{0.529\pgf@circ@res@up}}
    \pgfmoveto{\pgfpoint{0.216\pgf@circ@res@left}{0.666\pgf@circ@res@up}}
    \pgflineto{\pgfpoint{0.278\pgf@circ@res@left}{0.856\pgf@circ@res@up}}
    \pgfmoveto{\pgfpoint{0.216\pgf@circ@res@right}{0.666\pgf@circ@res@up}}
    \pgflineto{\pgfpoint{0.278\pgf@circ@res@right}{0.856\pgf@circ@res@up}}
    \pgfmoveto{\pgfpoint{0.566\pgf@circ@res@right}{0.411\pgf@circ@res@up}}
    \pgflineto{\pgfpoint{0.728\pgf@circ@res@right}{0.529\pgf@circ@res@up}}
    \pgfmoveto{\pgfpoint{0.7\pgf@circ@res@right}{0}}
    \pgflineto{\pgfpoint{0.9\pgf@circ@res@right}{0}}
    \pgfusepath{draw}
    \endpgfscope
    \pgfscope
        \pgftransformrotate{-\pgf@circ@direction}
    \pgfsetarrowsend{latex}
    \pgfmoveto{\pgfpointorigin}
    %\pgfmoveto{\pgfpoint{.1414\pgf@circ@res@left}{.1414\pgf@circ@res@up}}
    \pgflineto{\pgfpoint{.6363\pgf@circ@res@left}{.6363\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
  \pgfscope
    \pgftransformrotate{-\pgf@circ@direction}
    \pgftransformyshift{0.5\pgf@circ@res@down}
    \pgftext{\ctikzvalof{bipoles/meter/logo}}
  \endpgfscope
}

% create meter to-path style

\def\meterpath#1{\pgf@circ@bipole@path{meter}{#1}}
\compattikzset{meter/.style = {\circuitikzbasekey, /tikz/to path=\meterpath, \circuitikzbasekey/bipole/is voltage=true, v=#1}}
\makeatother

\begin{document}
\begin{circuitikz}
\draw (0,0) to[meter,o-*] (2,0);
\draw (3,-1) to[meter,o-*] (3,1);
\end{circuitikz}
\end{document}

\ctikzset{bipoles/meter/logo=Amp}顺便说一句,您可以使用例如来更改徽标。

相关内容