电压源对角连接时负极性符号的方向

电压源对角连接时负极性符号的方向

跟进问题。MWE 如下:

\documentclass[border=3mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\usepackage[american voltages, american currents, siunitx]{circuitikz}
%
%%% Independent voltage source - American style :: rotate polarity
%\makeatletter
%\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vsourceam/height}}{vsourceAM}{\ctikzvalof{bipoles/vsourceam/height}}{\ctikzvalof{bipoles/vsourceam/width}}{%
%   \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
%   \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}
%       {\pgfpoint{\pgf@circ@res@left}{0}}
%   \pgfusepath{draw}
%   \pgfscope
%       \pgftransformxshift{0.7*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
%       \pgftext[rotate=-\pgf@circ@direction]{$-$}
%       \pgfusepath{draw}
%   \endpgfscope
%   \pgfscope
%       \pgftransformxshift{0.7*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
%       \pgftext[rotate=-\pgf@circ@direction]{$+$}
%       \pgfusepath{draw}
%   \endpgfscope
%}
%\makeatother
%
%%% Controlled voltage source - American style :: rotate polarity
%
%\makeatletter
%\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/cvsourceam/height}}{cvsourceAM}{\ctikzvalof{bipoles/cvsourceam/height}}{\ctikzvalof{bipoles/cvsourceam/width}}{%
%   \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
%   \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
%   \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
%   \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
%   \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
%   \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
%   \pgfusepath{draw}
%   \pgfscope
%       \pgftransformxshift{0.7*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
%       \pgftext[rotate=-\pgf@circ@direction]{$-$}
%       \pgfusepath{draw}
%   \endpgfscope
%   \pgfscope
%       \pgftransformxshift{0.7*\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
%       \pgftext[rotate=-\pgf@circ@direction]{$+$}
%       \pgfusepath{draw}
%   \endpgfscope
%}
%\makeatother

\begin{document}
\begin{tikzpicture}[x=3.22cm,y=3.22cm]
\node[](a)at(0,0){};
\draw ($(a)+(0.0,0.0)$) node[circ]{}  to [cV, l=1<\volt>] ($(a)+(0.0,1.0)$) node[circ]{} 
    to [V, l_=2<\volt>] ($(a)+(1.0,1.0)$) node[circ]{} 
    to [cV, l_=3<\volt>] ($(a)+(2.0,1.0)$) node[circ]{} 
    to [V, l=4<\volt>, label/align=straight] ($(a)+(1.0,0.0)$) node[circ]{};
\draw ($(a)+(0.0,1.0)$) to [cV, l=1<\volt>, label/align=straight] ($(a)+(1.0,0.0)$);
\end{tikzpicture}
\end{document}

输出结果为

tikz+circuitikz 的默认输出

当取消注释上述 MWE 中的代码时,输​​出为:

修改了水平显示的极性符号

然而,我也在寻找下面类似这样的东西,用于对角连接的电压源:

期望输出

请问有什么建议吗?

答案1

声明一个新变量bipoles/vsources/minus/sign/rotation/.initial=0,然后将其插入到组件重新定义中,vsourceAMcvsourceAM在减号代码中旋转文本rotatebox:

... \pgftext[options]{\rotatebox{bipoles/vsources/minus/sign/rotation}{$-$}}

要启用旋转减号的选项,请在组件定义中将值更改为 90 度:

...
to [V,l_=$2V$,-*,bipoles/vsources/minus/sign/rotation=90] 
...

这里 MWE 使用为 circuitikz 定义的语法和相对坐标++(x_shift,y_shift),在这种情况下取​​决于的值\dist,着手4cm使用 获得更好的表示bipoles/length=2cm,请注意,要绘制短裤,使用符号*--**-*不是绘制圆圈;要更改大小,要更改的值为:nodes width/.initial=0.03

结果:2V 对角线控制源有符号修改,4V 对角线独立源为默认值 0。您可以选择看起来更好的。

在此处输入图片描述

梅威瑟:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage[american voltages, american currents, siunitx]{circuitikz}
\makeatletter
%% Independent voltage source - American style
\ctikzset{bipoles/vsources/minus/sign/rotation/.initial=0}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vsourceam/height}}{vsourceAM}{\ctikzvalof{bipoles/vsourceam/height}}{\ctikzvalof{bipoles/vsourceam/width}}{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfusepath{draw}
    \ifpgf@circ@oldvoltagedirection
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@down]{$+$}
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@up]{$-$}
    \else
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@down]{\rotatebox{\ctikzvalof{bipoles/vsources/minus/sign/rotation}}{$-$}}
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@up]{$+$}
    \fi
}

%% Controlled voltage source - American
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/cvsourceam/height}}{cvsourceAM}{\ctikzvalof{bipoles/cvsourceam/height}}{\ctikzvalof{bipoles/cvsourceam/width}}{
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfusepath{draw}

    \ifpgf@circ@oldvoltagedirection
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@left]{$+$}
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@right]{$-$}
    \else
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@left]{\rotatebox{\ctikzvalof{bipoles/vsources/minus/sign/rotation}}{$-$}}
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@right]{$+$}
    \fi
}
\makeatother

\begin{document}
\ctikzset{bipoles/length=2cm}
\ctikzset{nodes width/.initial=0.03}
\def\dist{4}
    \begin{tikzpicture}
    \draw
    (0,0)
        to [cV,l=$1V$,*-*] ++(0,\dist) coordinate (div-01)
        to [V,l_=$2V$,-*,bipoles/vsources/minus/sign/rotation=90] ++ (\dist,0)
        to [cV,l_=$3V$,-*,bipoles/vsources/minus/sign/rotation=90] ++ (\dist,0)
        to [V,l=$4V$,-*] ++ (-\dist,-\dist)
    (div-01)
        to [cV,l_=$2V$,-*,bipoles/vsources/minus/sign/rotation=90] ++ (\dist,-\dist);
    \end{tikzpicture}
\end{document}

相关内容