Circuitikz 中的接近符号

Circuitikz 中的接近符号

在 Circuitikz 中最好有一个接近符号。以下是示例:https://knowledge.autodesk.com/support/autocad-electrical/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/AutoCAD-Electrical/files/GUID-1B18023D-241C-4E50-822A-94F873FC258B-htm.html

我即兴使用 \ctikzsubcircuitdef,但嵌入符号就更好了。

\documentclass[10pt]{standalone}
\usepackage[siunitx,american, RPvoltages]{circuitikz}  

\begin{document}

\ctikzsubcircuitdef{proximeter}{in, out, center}{% reference anchor is -center
coordinate(#1-center)
(#1-center) +(-0.5,0)coordinate (#1-in)  +(0.5,0)coordinate (#1-out) 
(#1-in) to[ecsource] (#1-out)  
(#1-center)++(-0.35,0.15) to ++(0.7,0)
(#1-center)++(-0.35,-0.15) to ++(0.7,0)
% leave the position of the path at the center
(#1-center) 
}

\ctikzsubcircuitactivate{proximeter}
\begin{tikzpicture} 
  \draw[rotate=0] (2,0) \proximeter{PS}{};

  \draw[rotate=90] (0,0) \proximeter{PS}{};
  \draw (PS-in) --++(0,-1) coordinate(PS1) 
        (PS-out) --++(0,1) coordinate(PS2); 
\end{tikzpicture} 

\end{document}

答案1

此版本将添加到v1.5.2

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx, RPvoltages]{circuitikz}

\makeatletter
% proximeter shape, for usage with switches
\ctikzset{proximeter/width/.initial=0.3}
\ctikzset{proximeter/hlines thickness/.initial=0.5}
\ctikzset{proximeter/hlines position/.initial=0.3}
\pgfdeclareshape{proximeter}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{switches}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\hlinepos}{\edef\hlinepos{\ctikzvalof{proximeter/hlines position}}}
    \savedanchor\northeast{%
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{proximeter/width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
        \pgf@x=\pgf@y
    }
    \anchor{center}{\pgfpointorigin}
    % geo anchors based on north-east
    \pgfcirc@northeast@symmetric@geoanchors
    \anchor{text}{%
        \northeast
        \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
        \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
    }
    \anchor{hlines ne}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y
    }
    \anchor{hlines nw}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y\pgf@x=-\pgf@x
    }
    \anchor{hlines se}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y
        \pgf@y=-\pgf@y
    }
    \anchor{hlines sw}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y\pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{
        % \typeout{IN\space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgfmathsetmacro{\@@switchx}{ifthenelse(\pgf@x>0,1,-1)}
        \pgfmathsetmacro{\@@switchy}{ifthenelse(\pgf@y>0,1,-1)}
        \pgfmathsetlength{\pgf@xa}{abs(\pgf@x)}
        \pgfmathsetlength{\pgf@ya}{abs(\pgf@y)}
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        % \typeout{MID\space X:\the\pgf@xa\space Y:\the\pgf@ya\space L:\the\pgf@circ@res@up}
        % \typeout{MID\space SX:\@@switchx\space SY:\@@switchy}
        \pgfpointintersectionoflines
            {\pgfpointorigin}{\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{0pt}{\pgf@circ@res@up}}{\pgfqpoint{\pgf@circ@res@up}{0pt}}
        % \typeout{CROSS \space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgf@x=\@@switchx\pgf@x
        \pgf@y=\@@switchy\pgf@y
    }
    \pgf@circ@draw@component{
        \northeast\pgf@circ@res@temp=\pgf@y
        \pgf@circ@setcolor
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@temp}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@temp}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@temp}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfsetlinewidth{\ctikzvalof{proximeter/hlines thickness}*\pgflinewidth}
        \pgfmathsetlength{\pgf@circ@res@up}{\hlinepos*\pgf@circ@res@temp}
        \pgfmathsetlength{\pgf@circ@res@right}{\pgf@circ@res@temp-\pgf@circ@res@up}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfusepath{draw}
    }

}
\pgfcirc@node@to@path{proximeter}{inline proximeter}{}
\makeatother

\begin{document}
\begin{tikzpicture}
    \tikzset{small up proxi/.style={proximeter, solid,
            circuitikz/switches/scale=0.707,
            circuitikz/proximeter/hlines thickness=1,
            circuitikz/proximeter/hlines position=0.1}}
    \draw (0,0) to[inline proximeter, l=P1] ++(2,0)
        to[ccgsw, name=P2] ++(2,0);
    \draw[dashed] (P2.mid) -- ++(0,0.5)
        node[small up proxi, above](P2p){Fe}
        (P2p.north) ++ (0,0.5); % extend bounding box
\end{tikzpicture}
\end{document}

相关内容