我如何修改 circuitikz 中的 oscope 元素?

我如何修改 circuitikz 中的 oscope 元素?

我想修改oscopecircuitikz中的元素。它默认显示三角波,但我想让它显示正弦波。我该怎么做?

在此处输入图片描述

答案1

自 v1.3.5 起,您可以使用一组标准的“预加载”波形作为示波器:

在此处输入图片描述

可以通过语法来访问\ctikzset{bipoles/oscope/waveform=name

如果您想要更多,您可以定义新的形状;有关详细信息,请参阅手册(第 4.6.1.1 节“示波器波形”)但基本上:

\ctikzset{%
bipoles/oscope/waveform/mywave/.code={%
    \pgfsetcolor{red}
    \pgfpathmoveto{\pgfpoint{-.75cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{.75cm}{.5cm}}
    \pgfusepath{draw}
    \pgfsetcolor{green}
    \pgfpathmoveto{\pgfpoint{-.75cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.75cm}{-.5cm}}
    \pgfusepath{draw}
}}
\begin{circuitikz}
    \ctikzset{bipoles/oscope/waveform=mywave}
    \draw (0,0) node[oscopeshape]{};
\end{circuitikz}

这导致:

在此处输入图片描述

1.3.5 之前版本,最好的选择是按照手册中有关添加新双极子的说明进行操作 - 复制旧的,更改名称并重新定义图形元素。除非您对低级 pgf 命令有相当多的实践经验,否则这并不容易......

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}

\makeatletter
\pgfcircdeclarebipolescaled{instruments}
{
    \anchor{in 1}{\southwest\pgf@y=0.75\pgf@y\pgf@x=0.4\pgf@x}
    \anchor{in 2}{\southwest\pgf@y=0.75\pgf@y\pgf@x=-0.4\pgf@x}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/oscope/height}}
{oscopesin}
{\ctikzvalof{bipoles/oscope/height}}
{\ctikzvalof{bipoles/oscope/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@down}{\southwest}
    \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
    \pgfscope
        \pgfsetcornersarced{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@step}}
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        % this would create a round (analog?) scope...
        % \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    % get the rotation
    \ifpgf@circuit@straightinstruments
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    \else
        \edef\rot{0}
    \fi
    % and unrotate the scope
    \pgfscope
        \pgftransformrotate{\rot}
        % grid
        \pgfscope
            \pgfsetlinewidth{0.5\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{0.25\pgf@circ@res@down}}
            \pgfpathgrid[stepx=\pgf@circ@res@step, stepy=\pgf@circ@res@step]%
            {\pgfpoint{0.75\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
            {\pgfpoint{0.75\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
            \pgfsetstrokeopacity{0.5}
            \pgfusepath{draw}
        \endpgfscope
        % function displayed
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@left}{0\pgf@circ@res@down}}
        \pgfpathsine{\pgfpoint{-0.3\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-0.3\pgf@circ@res@left}{-0.4\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-0.3\pgf@circ@res@left}{-0.4\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-0.3\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}
\pgfcirc@activate@bipole@simple{l}{oscopesin}
\makeatother



\begin{document}
\begin{tikzpicture}[]
    \draw (0,0) node[oscopesinshape]{};
    \draw (1,0) to[oscopesin] ++(0,-2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容