绘制传输线电路

绘制传输线电路

这是传输线电路的一个例子:

(另有一个可用这里)。传输线通常用两个水平平行的圆柱体绘制,长度可变且可调整。我没有在circuitikz。在手动的(第 8 页),提供了单个transmission line stub,但它是一个长度固定的小型单个圆柱体。

circuitikz如何用或绘制上述示例电路tikz

答案1

这样怎么样?我编辑了抽屉的原始版本tline,使圆柱体的长度由线段的长度决定。

\documentclass{article}
\usepackage{circuitikz}
\usepackage{etoolbox}
\makeatletter

\pgfcircdeclarebipole{}
    {\ctikzvalof{bipoles/tline/height}}{tline}
    {\ctikzvalof{bipoles/tline/height}}
    {\ctikzvalof{bipoles/tline/width}}
{   
    %% First find distance from startpoint to endpoint
    \pgfpointdiff{\pgfpointanchor{\ctikzvalof{bipole/name}start}{center}}
                 {\pgfpointanchor{\ctikzvalof{bipole/name}end}{center}}
    \pgfmathparse{veclen(\the\pgf@x,\the\pgf@y)}
    %% The coordinate system has been changed so that the origin is at the midpoint and
    %% the line is along the x axis. So shift back by half the length of the line, and 
    %% make the cylinder of width roughly the length of the line, with a 40pt setback
    %% on each side.
    \pgftransformxshift{\pgfmathresult/2-30pt}
    \pgf@circ@res@left=\dimexpr-\pgfmathresult pt+40pt\relax
    %% Here is the original function, copied directly from the source of circuittikz, 
    %% down to next %%
    \pgf@circ@res@step=.2\pgf@circ@res@right % half x axis
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathellipse{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{0}}
                   {\pgfpoint{\pgf@circ@res@step}{0}}
                   {\pgfpoint{0}{-\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpatharc{-90}{90}{-\pgf@circ@res@step and -\pgf@circ@res@up}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@down}}
    %% I have to fill the figure to block out the original line
    \pgfsetfillcolor{white}
    \pgfusepath{draw,fill}
    %% Redraw part of the line that gets blocked by the cylinder by mistake
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2*\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[TL] (10,0) to[TL] (14,4);
\end{circuitikz}
\end{document} 

答案2

如果其他人需要这个,我修改了 Hood 的解决方案(只是改变了绘制顺序、线条粗细),使传输线的末端看起来像原来的一样。这是我的结果:

传输线电路

代码如下:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{etoolbox}
\makeatletter

\pgfcircdeclarebipole{}
    {\ctikzvalof{bipoles/tline/height}}{tline}
    {\ctikzvalof{bipoles/tline/height}}
    {\ctikzvalof{bipoles/tline/width}}
{   
    %% First find distance from startpoint to endpoint
    \pgfpointdiff{\pgfpointanchor{\ctikzvalof{bipole/name}start}{center}}
                 {\pgfpointanchor{\ctikzvalof{bipole/name}end}{center}}
    \pgfmathparse{veclen(\the\pgf@x,\the\pgf@y)}
    %% The coordinate system has been changed so that the origin is at the midpoint and
    %% the line is along the x axis. So shift back by half the length of the line, and 
    %% make the cylinder of width roughly the length of the line, with a 40pt setback
    %% on each side.
    \pgftransformxshift{\pgfmathresult/2-30pt}
    \pgf@circ@res@left=\dimexpr-\pgfmathresult pt+40pt\relax

    %% Here is the original function, copied directly from the source of circuittikz, 
    %% down to next %%
    \pgf@circ@res@step=.2\pgf@circ@res@right % half x axis
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpatharc{-90}{90}{-\pgf@circ@res@step and -\pgf@circ@res@up}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@down}}
    \pgfsetfillcolor{white}
    \pgfusepath{draw,fill}

    %% I have to fill the figure to block out the original line
    \pgfpathellipse{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{0}}
                   {\pgfpoint{\pgf@circ@res@step}{0}}
                   {\pgfpoint{0}{-\pgf@circ@res@up}}
    \pgfsetfillcolor{white}
    \pgfusepath{draw, fill}

    %% Redraw part of the line that gets blocked by the cylinder by mistake
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-1*\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

\begin{document}
\begin{circuitikz}
\draw (0,0) to[TL] (10,0) to[TL] (14,4);
\end{circuitikz}
\end{document} 

相关内容