Circuitikz 上的四极子(双极子)、空盒或黑盒设备,带有耦合端子

Circuitikz 上的四极子(双极子)、空盒或黑盒设备,带有耦合端子

所有版本的软件包似乎都缺少一个非常通用的电路描述(黑盒模型)的简单基本组件,如四极子或单端口盒子(但有两个端子突出了设备的电气特性,而不仅仅是一个,就像组件“双端口”一样)。我想画这样的东西,可以吗? 在此处输入图片描述

答案1

以下是如何使用普通矩形节点:

\documentclass{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}% or tikzpicture
\tikzset{quad/.style={draw, thick, minimum height=.8cm, minimum width=.8cm}}
\node[quad] (A) at (0,0) {text};
\draw ($(A.north west)!.5!(A.west)$) to[short,-o] ++(-.2,0)
      ($(A.south west)!.5!(A.west)$) to[short,-o] ++(-.2,0)
      ($(A.north east)!.5!(A.east)$) to[short,-o] ++(.2,0)
      ($(A.south east)!.5!(A.east)$) to[short,-o] ++(.2,0);
\end{circuitikz}
\end{document}

演示


以下是如何创建具有内置引线和 4 个新锚点(in1、in2、out1 和 out2)的新形状。

\documentclass{standalone}
\usepackage{circuitikz}

\makeatletter
% ************************** blackbox *****************************
\ctikzset{quadpoles/blackbox/.is family}
\ctikzset{quadpoles/blackbox/height/.initial=.5}
\ctikzset{quadpoles/blackbox/width/.initial=.5}
\ctikzset{quadpoles/blackbox/sep/.initial=2pt}
\ctikzset{quadpoles/blackbox/lead/.initial=.5}

\pgfdeclareshape{blackbox}{
\anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center

\anchor{text}   % this is used to center the text in the node
    {\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}

\savedmacro{\resize}{\pgf@circ@res@temp=\ctikzvalof{bipoles/length}% scale
  \pgf@circ@res@temp=0.5\pgf@circ@res@temp
  \pgf@circ@res@right=\ctikzvalof{quadpoles/blackbox/width}\pgf@circ@res@temp
  \pgf@circ@res@step=0.5\wd\pgfnodeparttextbox
  \advance\pgf@circ@res@step by \ctikzvalof{quadpoles/blackbox/sep}%
  \ifdim\pgf@circ@res@right<\pgf@circ@res@step \pgf@circ@res@right=\pgf@circ@res@step\fi
  \pgf@circ@res@left=-\pgf@circ@res@right
  \pgf@circ@res@up=\ctikzvalof{quadpoles/blackbox/height}\pgf@circ@res@temp
  \pgf@circ@res@step=0.5\ht\pgfnodeparttextbox
  \advance\pgf@circ@res@step by \ctikzvalof{quadpoles/blackbox/sep}%
  \ifdim\pgf@circ@res@up<\pgf@circ@res@step \pgf@circ@res@up=\pgf@circ@res@step\fi
  \pgf@circ@res@down=-\pgf@circ@res@up
  \pgfstartlinewidth=\pgflinewidth% don't know why this is needed
}

\savedanchor{\northeast}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\savedanchor{\southwest}{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

\anchor{north east}{\northeast}
\anchor{south west}{\southwest}
\anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfpoint{0cm}{\pgf@circ@res@up}}
\anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfextractx{\pgf@circ@res@left}{\southwest}\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}\pgfpoint{\pgf@circ@res@left}{0cm}}
\anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfpoint{0cm}{\pgf@circ@res@down}}
\anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{0cm}}

\savedanchor{\inone}{%
  \pgf@circ@res@step=-\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@left
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@up}
}
\anchor{in1}{\inone}

\savedanchor{\intwo}{%
  \pgf@circ@res@step=-\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@left
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@down}
}
\anchor{in2}{\intwo}

\savedanchor{\outone}{%
  \pgf@circ@res@step=\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@right
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@up}
}
\anchor{out1}{\outone}

\savedanchor{\outtwo}{%
  \pgf@circ@res@step=\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@right
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@down}
}
\anchor{out2}{\outtwo}

\foregroundpath{% border and leads drawn here
  \pgfextractx{\pgf@circ@res@right}{\northeast}
  \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@down}{\southwest}

  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}%
  \pgfpathrectanglecorners{\southwest}{\northeast}%
  \pgfusepath{draw}%
  \pgfscope
    \pgfsetlinewidth{\pgfstartlinewidth}%
    \pgfpathmoveto{\inone}%
    \pgfextracty{\pgf@circ@res@step}{\inone}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\intwo}%
    \pgfextracty{\pgf@circ@res@step}{\intwo}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\outone}%
    \pgfextracty{\pgf@circ@res@step}{\outone}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\outtwo}%
    \pgfextracty{\pgf@circ@res@step}{\outtwo}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@step}}%
    \pgfusepath{draw}%
  \endpgfscope
}}
\makeatother

\begin{document}
\begin{circuitikz}% or tikzpicture
\node[blackbox] (A) at (0,0) {text};
\node[blackbox,anchor=in1] (B) at (A.out1) {more text};
\end{circuitikz}
\end{document}

形状

相关内容