# How to connect a transformer the “right” way using circuitikz?

I have been using this template I found to build a power eletronics schematics (source: http://www.texample.net/tikz/examples/ac-drive-components/)

Now, what is the best way to connect the transformer?

I used a fixed coordinate (2,4.2) to draw lines from there to the transformer pole A1. That works, but what about the A2 connector of "T"? I don't know it's cooridinate and I also want to make sure it's symmetrical (distance from MOSFET to transformer connection is equal on both ends).

So I tried to connet it to the MOSFET's drain using (mosfet4.D), works well but of course, the transformer is not where it needs to be, so the line is not straight.

How do I solve this? Don't want to make this too complicated, I'd like to use the built in anchors if possible.

Thank you.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[siunitx,european,fetbodydiode]{circuitikz}
\begin{document}
\begin{figure}
% Generalized diagram of different components inside an AC drive with voltage intermediate circuit
% Based on a template by
% Author: Erno Pentzin (2013), http://www.texample.net/tikz/examples/ac-drive-components/

\begin{circuitikz}
\draw
% DC sources
(0,0) to[open, v=60<\volt>, *-*, invert] ++(0,6) coordinate (Vcc) ++(2,0) coordinate (NE)

% Switches and diodes for leg a
++(0,-1) node[nigfete,name=mosfet1] {$Q_1$}
%(mosfet1) node[anchor=east]{test} muss noch platziert werden, oder so lassen wie label oben
++(0,-4) node[nigfete,name=mosfet2] {$Q_2$}

% --Switch connections for leg a
(Vcc) -| (mosfet1.C)
(mosfet1.E) -- (mosfet2.C)
(mosfet2.E) |- (0,0)

% Switches and diodes for leg b
(NE)++(3,0)
++(0,-1) node[nigfete,name=mosfet3] {$Q_3$}
++(0,-4) node[nigfete,name=mosfet4] {$Q_4$}

% --Switch connections for leg b
(Vcc) -| (mosfet3.C)
(mosfet3.E) -- (mosfet4.C)
(mosfet4.E) |- (0,0)

% Inductor, grid, and the return path
(2,4.2)
%to[short, *-, i_=$i_o(t)$, current/distance=0.5]
++(4.5,0) node[transformer core,name=T]{}

% connect transformer
(mosfet1.S) -- (T.A1)
(T.A2) -- (mosfet4.D)

% P and arrow
% (Lright)++(0.2,0) to[open, o-o] ++(0,-2)
%(Lright)++(0.2,-1) node [text width=2pt] {$\Rightarrow P$}

% v_o(t)
(6.5,2.2) to[open, v^=$v_o(t)$] ++(0,-2)
;
\end{circuitikz}
\caption[Ersatzschaltbild]{Ersatzschaltbild}
\label{fig:ersatzschaltbild}
\end{figure}
\end{document}


edit: considering your comment, your image should be somthing like this (finally uploaded ...):

since i'm lost in your code i had less problems to draw it from scratch :-(. new mwe is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[siunitx,european,fetbodydiode]{circuitikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{figure}
\begin{circuitikz}
\draw
% top part of switch legs
(0,0)                                           coordinate (s1)
to              ++ (0,-0.4)
node (mosfet1) [nigfete,below,anchor=D] {$Q_1$}
(mosfet1)           node (mosfet3) [nigfete,right=22mm]     {$Q_3$}
(mosfet1.S)         to [short,-*]   ++ (0,-0.4) coordinate (t1)
% transformer
(t1 -| mosfet3.S)   node (T) [transformer core,below right=0mm and 11mm]{}
% bottom part of switch legs
(mosfet3.S |- T.A2)                             coordinate (t2)
to              ++ (0,-0.4)
node (mosfet4) [nigfete,below,anchor=D] {$Q_4$}
(t1 |- mosfet4.D)   node (mosfet2) [nigfete,below,anchor=D] {$Q_2$}
% connection lines origins at transformer
(T.A1) to                       (t1)
(T.A2) to [short,-*]            (t2)
(T.B1) to [short,-o]                ++ (0.5,0)  coordinate (t3)
(T.B2) to [short,-o]                ++ (0.5,0)  coordinate (t4)
(t3)   to[open, v^=$v_o(t)$]    (t4)
% connection lines orign at mosfet
(t1)        to      (mosfet2.D)
(mosfet2.S) to ++   (0,-0.4)                    coordinate (s2)
(mosfet3.D) to ++   (0, 0.4)                    coordinate (s3)
(mosfet3.S) to      (mosfet4.D)
(mosfet4.S) to ++   (0,-0.4)                    coordinate (s4)
% supply lines
(s3) -- (s1) to [short,-o] ++ (-2,0)            coordinate (s+)
(s4) -- (s2) to [short,-o] ++ (-2,0)            coordinate (s-)
(s-) to [open, v=60<\volt>, invert] (s+)
;
\end{circuitikz}
\caption[Ersatzschaltbild]{Ersatzschaltbild}
\label{fig:ersatzschaltbild}
\end{figure}
\end{document}

• Thanks, that's pretty much it. Can you explain, what the (T.A2 -| mosfet4.D) inside the () (brackets) do? Are these brackets needed? Also, is there a way, to keep using the fixed mosfet anchors? As you can see, the distance from Q4 to the wire differs from that of Q1 to the connection, as of course in this example I have used a fixed coordinate to connect A1 to the Source of Q1. How can I make this even? – SF6 Oct 9 '17 at 10:38
• (T.A2 -| mosfet4.D) is coordinate of intersections of horizontal line through T.A2 and vertical line through mosfet4.D. this syntax is documented in tikz & pgf manual (v3.0.1a) in subsection13.3.1 Intersections of Perpendicular Lines, page 137 -- 138. for new question: it is simple to achieve, you only need to add new coordinates in images, but for this temporary i haven't time. maybe at evening. sorry. – Zarko Oct 9 '17 at 10:51
• Thanks a lot, this is exactly how I wanted it to be. Basically, you plotted it not the way it electrically behaves, but how it's easier to draw, right? First, I had trouble understanding your step (t1 -| mosfet3.S), connecting t1, which is Source of Q1 to Drain of Q3, but it seems easier to continue from there. – SF6 Oct 9 '17 at 20:01
• you have (in general) two possibilities to draw electrical schemes: (i) in advance determine all coordinates between which are electrical elements or (ii) start draw with some element and then positioning next to it and so on. my drawing is based on second possibilities. elements are draw in order: nodes in clock wise direction from top left to bottom left, connections lines are drawn separately but in the same order. i named the most of used coordinates, but not all. a case no named coordinates is (t1 -| mosfet3.S) because it is used only for placement transformer. – Zarko Oct 9 '17 at 21:05
• Ok, this makes sense. Can you show me the syntax for positioning a diode next to another one? Like in your MEW, you used node (mosfet1) [nigfete,below,anchor=D] {$Q_1$} (mosfet1) node (mosfet3) [nigfete,right=22mm] {$Q_3$} to position switch Q3 next to switch Q2. But how do I achieve this with a diode, which is not a node? What I did on the secondary side is to position (t3) to [Do] ++(0,1.5) and now I want another Do in a certain distance to the the first one. I also placed on on the bottom, using (t4) to [Do,invert] ++(0,-1.5) which I inverted, is that alright like this? – SF6 Oct 9 '17 at 21:35