# Orientation of negative polarity notation in voltage source when connected diagonally

Follow up of this question. MWE is give below:

\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}


which gives the output as

when uncommented the codes in the above MWE, the output is:

however, I am looking for something like this below for diagonally connected voltage sources as well:

• I don't know tikz, but looks like a little bit different rotate angle, have a look at the rotate calls in the answer of your precious question. Oct 1 '18 at 16:55
• @albert, actually that rotate helps in rotating the polarity in horizontal display. Acually, I am at a lost for diagonal rotation. If - notation is removed, the -ve sign on diagonal voltage source becomes vertical which is undesirable in fact Oct 1 '18 at 17:02
• @albert, diagonal is fixed with \pgftext[rotate=-0.28*\pgf@circ@direction]{$-$} however, source in perpendicular display like 1V source has a problem Oct 1 '18 at 17:14
• The modification was specifically to ALWAYS draw the symbols right side up. Trying to guess the most esthetically pleasing angle is a much harder question. Oct 1 '18 at 17:39
• @JohnKormylo, true. With my limited knowledge in tikz-pgf, trying to get a book like circuit diagram display becomes impossible Oct 1 '18 at 17:46

Declaring a new variable bipoles/vsources/minus/sign/rotation/.initial=0 and then insert it in the component redefinition for vsourceAM and cvsourceAM in the code for the minus sign to rotate the text using rotatebox:

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


to enable the option to rotate the minus changing the value to 90 degrees inside the component defintition:

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


Here a MWE using the defined sintax for circuitikz and with relative coordinates ++(x_shift,y_shift), in this case depending of the value of \dist, setted out to 4cm to get better presentation using bipoles/length=2cm, remark that to draw the shorts the notation *-, -*, *-* is used instead drawing circles; to change the size the value to change is: nodes width/.initial=0.03.

RESULT: The 2V diagonal cotrolled source has sign modification and the 4V diagonal independient source is in the default value 0. you can choose what has better look.

MWE:

\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}