3

Source signs behavior

Hello, friends. Well, a picture is worth a thousand words. I would like the behavior on the left rather than on the right, the latters are CircuitTikZ defaults. A helpful guy helped me to do it with independent voltage sources,unfortunately I forgot about asking him for these ones. Does anyone have the same concern out there?

Thanks in advance.

\documentclass{article}
\usepackage{circuitikz}
\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{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
        \pgftext[rotate=-\pgf@circ@direction]{$-$}
        \pgfusepath{draw}
    \endpgfscope
    \pgfscope       \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
        \pgftext[rotate=-\pgf@circ@direction]{$+$}
        \pgfusepath{draw}
    \endpgfscope
}
\makeatother
\begin{document}
\begin{circuitikz}[american voltages]
\ctikzset{bipoles/vsourceam/margin=.5}% default too big
\draw (0,0) to[V={v1}] (3,0) to[V={v2}] (3,3) to[V={v3}] (0,3) to[V={v4}] (0,0);
\draw (4,0) to[V={v5}] (6,2);
\end{circuitikz}
\end{document}

As specific code.

  • It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Nov 13 '14 at 18:29
  • @PeterGrill, check out the code. – mov0021 Nov 13 '14 at 19:41
  • You should also update the image to correspond to the give MWE. – Peter Grill Nov 13 '14 at 21:04
  • I do not have it because I do not know how to do it, thus far. – mov0021 Nov 14 '14 at 0:59
2
  1. Eliminating the rotation by setting rotate=0 yields:

    enter image description here

  2. If you desire the +, - symbols to be perpendicular to the path you can instead use rotate=90:

    enter image description here

  3. As per you comment, if you want the + and - signs to always be in the normal non-rotated position then setting rotate=-\pgf@circ@direction (which is what your provided in the MWE above) seems to do just that:

    enter image description here

Code:

\documentclass{article}
\usepackage{circuitikz}
\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{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@left}
        \pgftext[rotate=0]{$-$}
        \pgfusepath{draw}
    \endpgfscope
    \pgfscope       \pgftransformxshift{\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@right}
        \pgftext[rotate=0]{$+$}
        \pgfusepath{draw}
    \endpgfscope
}
\makeatother
\begin{document}
\begin{circuitikz}[american voltages]
\ctikzset{bipoles/vsourceam/margin=.5}% default too big
\draw (0,0) to[V={v1}] (3,0) to[V={v2}] (3,3) to[V={v3}] (0,3) to[V={v4}] (0,0);
\draw (4,0) to[V={v5}] (6,2);
\end{circuitikz}
\end{document}
  • Hmmm, almost there. What I meant was never to rotate the signs in order to make them look always like a “+” an like a “−”. – mov0021 Nov 14 '14 at 0:57
  • @mov0021: I am a bit confused -- your MWE as provided already does that (revised answer to document that option). – Peter Grill Nov 14 '14 at 1:17
  • Yes, it works with the independent source, but it does not with the controlled voltage source. @PeterGrill – mov0021 Nov 15 '14 at 4:38
2

This is a simpler approach by defining one's own control voltage called myctrv that modifies the existing control voltage in circuitikz (cV).

\newcommand{\myctrv}[3] % #1 = name , #2 = rotating of the symbol, 
  #3 = rotation of negative polarity.
{
\begin{scope}[transform shape,rotate=#2]
\draw[] (#1){};
\draw[thick] (#1) +(14pt,0)-- +(0,14pt)-- +(-14pt,0)-- +(0,-14pt)-- cycle;
\draw[]  (#1) +(6pt,0) node(){\rotatebox{#2}{$+$}}
         (#1) +(-6pt,0) node(){\rotatebox{#3}{$-$}};
\end{scope}
}

enter image description here

Code

\documentclass[border=5mm]{standalone}  
\usepackage[american,siunitx]{circuitikz}

\newcommand{\myctrv}[3]  % #1 = name , #2 = rotating of the symbol, 
 #3 = rotation of negative polarity.
{
\begin{scope}[transform shape,rotate=#2]
\draw[] (#1){};
\draw[thick] (#1) +(14pt,0)-- +(0,14pt)-- +(-14pt,0)-- +(0,-14pt)-- cycle;
\draw[]  (#1) +(6pt,0) node(){\rotatebox{#2}{$+$}}
         (#1) +(-6pt,0) node(){\rotatebox{#3}{$-$}};
\end{scope}
}

\begin{document}  
\begin{circuitikz}[american voltages]
\draw (0,0) 
to[cV,color=white,name=mycv1,l={v1}] (3,0) 
to[cV,color=white,name=mycv2,l={v2}] (3,3) to[cV,color=white,name=mycv3,l={v3}] (0,3) to[cV,color=white,name=mycv4,l={v4}] (0,0);
\draw (4,0) 
to[cV,color=white,name=mycv5,l=\raisebox{-0.6cm}{\rotatebox{-45}{v5}}] (6,2);
\myctrv{mycv1}{0}{0}
\myctrv{mycv2}{90}{90}
\myctrv{mycv3}{180}{180}
\myctrv{mycv4}{270}{270}
\myctrv{mycv5}{45}{-45}
\end{circuitikz}
\end{document}
  • Unbelievable, my friend. Thank you so much. :) – mov0021 Jan 11 '15 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.