如何在我的 circuitikz 电路图中包含示波器?

如何在我的 circuitikz 电路图中包含示波器?

我想在我的电路图中包含一个示波器符号,如下所示:

示波器

我环顾四周,似乎没有内置的。有可能将这样的东西放入 circuitikz 吗?

答案1

这可以作为一个起点。该提案定义了一个myscope宏,它采用两个参数来绘制一个现有元素sV,将其涂成白色,然后在其上绘制一条三角曲线。

在此处输入图片描述

代码

\documentclass[border=20pt]{standalone}  
\usepackage[american,siunitx]{circuitikz}
\usetikzlibrary{arrows,shapes,calc,positioning}

\newcommand{\myscope}[2] % #1 = name , #2 = rotation angle
{\draw[thick,rotate=#2] (#1) circle (12pt)
 (#1) ++(-0.35,-0.1) -- ++(0.3,0.3) --++(0,-0.3)-- ++(0.3,0.3) --++(0,-0.3);
}
\begin{document}

\begin{circuitikz}
\draw (0,2) to[L, l_=$L$, o-*] (2,2) to[sV, color=white, name=S1] (3.5,2) to[short,*-] (5,2);
\myscope{S1}{0}
\draw (0,0) to[short, o-*] (2,0) to[short, -*] (3.5,0) to[short] (5,0);
\draw (2,2) to[C=$C$] (2,0);
\draw (3.5,2) to[R=$R$] (3.5,0);
\draw (5,2) to[sV, color=white, name=S2] (5,0);
\myscope{S2}{0}
\end{circuitikz}

\end{document}

答案2

这是一个糟糕的解决方案。它不具备可扩展性。

更好的:

定义一个新的符号:

\makeatletter
% used to process styles for to-path
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
% restore size value for bipole definitions
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\makeatother
\newlength{\ResUp} \newlength{\ResDown}
\newlength{\ResLeft} \newlength{\ResRight}

\ctikzset{bipoles/SCOPE/height/.initial=.60}
\ctikzset{bipoles/SCOPE/width/.initial=.60}
\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/SCOPE/height}}
{SCOPE}
{\ctikzvalof{bipoles/SCOPE/height}}
{\ctikzvalof{bipoles/SCOPE/width}}
{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfextracty{\ResUp}{\northeast}    %ResUp make usable
    \pgfextractx{\ResRight}{\northeast} %ResRight make usable
    \pgfextractx{\ResLeft}{\southwest}  %ResLeft make usable
    \pgfextracty{\ResDown}{\southwest}  %ResDown make usable
    \pgfpathmoveto{\pgfpoint{0.75\ResLeft}{0.25\ResDown}}
    \pgfpathlineto{\pgfpoint{0.05\ResLeft}{0.25\ResUp}}
    \pgfpathlineto{\pgfpoint{0.05\ResLeft}{0.25\ResDown}}
    \pgfpathlineto{\pgfpoint{0.65\ResRight}{0.25\ResUp}}
    \pgfpathlineto{\pgfpoint{0.65\ResRight}{0.25\ResDown}}
    \pgfpathmoveto{\pgfpoint{1.25\ResLeft}{0.5\ResDown}}
    \pgfpathlineto{\pgfpoint{1.75\ResLeft}{0.5\ResDown}}
    \pgfpathmoveto{\pgfpoint{1.5\ResLeft}{0.25\ResDown}}
    \pgfpathlineto{\pgfpoint{1.5\ResLeft}{0.75\ResDown}}
    \pgfpathmoveto{\pgfpoint{1.25\ResRight}{0.75\ResDown}}
    \pgfpathlineto{\pgfpoint{1.75\ResRight}{0.75\ResDown}}
    \pgfpathmoveto{\pgfpoint{1.5\ResRight}{0.45\ResDown}}
    \pgfpathlineto{\pgfpoint{1.5\ResRight}{0.75\ResDown}}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\ResUp}}{\pgfpoint{\ResLeft}{0}}
    \pgfusepath{draw}
}
\def\SCOPEpath#1{\TikzBipolePath{SCOPE}{#1}}
\tikzset{SCOPE/.style = {\circuitikzbasekey, /tikz/to path=\SCOPEpath, l=#1}}
%#########################################################################################

并将其纳入你的电路中:

    \begin{circuitikz}[xscale=5,yscale=3, every node/.style={font=\footnotesize}]   %define scaling
            \draw (0,0) to[SCOPE, l=CH1, *-*] (2,0);
    \end{circuitikz}

享受!

答案3

对已经提到的解决方案稍作修改。

此版本应该使示波器符号旋转不变。

\makeatletter
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}

\newlength{\ResUp} \newlength{\ResDown}
\newlength{\ResLeft} \newlength{\ResRight}
\ctikzset{bipoles/SCOPE/height/.initial=.60}
\ctikzset{bipoles/SCOPE/width/.initial=.60}
\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/SCOPE/height}}
{SCOPE}
{\ctikzvalof{bipoles/SCOPE/height}}
{\ctikzvalof{bipoles/SCOPE/width}}
{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfextracty{\ResUp}{\northeast}    %ResUp make usable
    \pgfextractx{\ResRight}{\northeast} %ResRight make usable
    \pgfextractx{\ResLeft}{\southwest}  %ResLeft make usable
    \pgfextracty{\ResDown}{\southwest}  %ResDown make usable
    \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
        \ifnum \pgfcircmathresult > 45 \ifnum \pgfcircmathresult < 135
            \pgftransformrotate{270}
        \fi\fi
        \ifnum \pgfcircmathresult > 135 \ifnum \pgfcircmathresult < 225
            \pgftransformrotate{180}
        \fi\fi
        \ifnum \pgfcircmathresult > 225 \ifnum \pgfcircmathresult < 315
            \pgftransformrotate{90}
        \fi\fi
    \pgfpathmoveto{\pgfpoint{0.75\ResLeft}{0.25\ResDown}}
    \pgfpathlineto{\pgfpoint{0.05\ResLeft}{0.25\ResUp}}
    \pgfpathlineto{\pgfpoint{0.05\ResLeft}{0.25\ResDown}}
    \pgfpathlineto{\pgfpoint{0.65\ResRight}{0.25\ResUp}}
    \pgfpathlineto{\pgfpoint{0.65\ResRight}{0.25\ResDown}}

    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\ResUp}}{\pgfpoint{\ResLeft}{0}}
    \pgfusepath{draw}
}
\def\SCOPEpath#1{\TikzBipolePath{SCOPE}{#1}}
\tikzset{SCOPE/.style = {\circuitikzbasekey, /tikz/to path=\SCOPEpath, l=#1}}
\makeatother

旋转的灵感来自于https://github.com/circuitikz/circuitikz/blob/master/tex/pgfcircbipoles.tex

相关内容