circuitikz 的新开关组件

circuitikz 的新开关组件

我在 circuitikz 中寻找一个normally closed switch,但带有闭合或打开箭头。由于我找不到它们,所以我自己编写了它们。它主要是normally closed switchopening spst/的复制粘贴。请注意,这些符号比目前实现的closing spst略宽。normally closed switch

\documentclass{standalone}
\usepackage{tikz}
\usepackage{circuitikz}


\ctikzset{bipoles/oncs/height/.initial=.35}
\ctikzset{bipoles/oncs/width/.initial=.45}
\ctikzset{bipoles/oncs/depth/.initial=.2}

\makeatletter

%% Opening NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{oncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-10}{1.2\pgf@circ@res@right}}
        \pgfpatharc{-10}{90}{1.2\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{cncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{1.2\pgf@circ@res@right}}
        \pgfpatharc{90}{-20}{1.2\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

\pgfcirc@activate@bipole@simple{l}{oncs}
\pgfcirc@style@to@style{oncs}{opening normal closed switch}
\pgfcirc@activate@bipole@simple{l}{cncs}
\pgfcirc@style@to@style{cncs}{closing normal closed switch}

\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,2) to[ncs] (1,2) node[anchor = west] {normally closed switch};
    \draw (0,1) to[cncs] (1,1) node[anchor = west] {closing normally closed switch};
    \draw (0,0) to[oncs] (1,0) node[anchor = west] {opening normally closed switch};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

我主张让开关的大小保持原样(基本上是为了向后兼容)并使用稍小的弧:

\documentclass[border=2.78mm]{standalone}
\usepackage{tikz}
\usepackage{circuitikz}


\ctikzset{bipoles/oncs/height/.initial=.35}
\ctikzset{bipoles/oncs/width/.initial=.35}
\ctikzset{bipoles/oncs/depth/.initial=.2}

\makeatletter

%% Opening NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{oncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-20}{.9\pgf@circ@res@right}}
        \pgfpatharc{-10}{90}{.9\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{cncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{.9\pgf@circ@res@right}}
        \pgfpatharc{90}{-35}{.9\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

\pgfcirc@activate@bipole@simple{l}{oncs}
\pgfcirc@style@to@style{oncs}{opening normal closed switch}
\pgfcirc@activate@bipole@simple{l}{cncs}
\pgfcirc@style@to@style{cncs}{closing normal closed switch}

\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,2) to[ncs] (1,2) node[anchor = west] {normally closed switch};
    \draw (0,1) to[cncs] (1,1) node[anchor = west] {closing normally closed switch};
    \draw (0,0) to[oncs] (1,0) node[anchor = west] {opening normally closed switch};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容