18

Is there a "easy" way draw something like the following in TikZ? I only have the frame but those swirly things are hard to draw:

enter image description here

\centering
\begin{tikzpicture}

\draw (0,0) --(0,5) -- (7,5) -- (7,0) -- (0,0) ;
\draw (1,1) -- (1,4) -- (3,4) -- (3,1) -- (1,1) ;
\draw (4,1) -- (4,4) -- (6,4) -- (6,1) -- (4,1) ;
\draw[very thick] (8,4.8) -- (8,2.8);
\draw[very thick] (8,2.2) -- (8,.2);
\draw[very thick] (9,4.8) -- (9,2.8);
\draw[very thick] (9,2.2) -- (9,.2);
\draw[very thick] (10,4.8) -- (10,2.8);
\draw[very thick] (10,2.2) -- (10,.2);
\draw[thick] (-0.3,3.5) -- (1,3.5);
\draw[thick] (1,3.5) to [out=180,in=45] (1.2,3.3);
\end{tikzpicture}
  • You may want to read about the "Circuit Libraries" in the pgf manual. – Christian Feuersänger Jan 15 '14 at 19:07
15

If a PSTricks solution is an option, you can use the following:

\documentclass{article}

\usepackage[margin = 3cm]{geometry}
\usepackage{pstricks-add}

\let\Name\MakeUppercase

%%% values needed (automatically calculated)
\usepackage{xfp}

% picture frame
\newcommand*\DiagramHorizontalStart{
  \fpeval{-\WindingRadius-5080/7227}% (5080/7227)mm = 2pt = \psdot diameter (if I am not mistaken)
}
\newcommand*\DiagramHorizontalEnd{
  \fpeval{3*\CoreThickness+2*\CoreholeHorizontal+\WindingRadius
          +\ElectroamgnetComponentDistance+3*\ComponentThickness
          +2*\ComponentsHorizontalDistance+0.1}
}
\newcommand*\DiagramVerticalEnd{
  \fpeval{2*\CoreThickness+\CoreholeVertical}
}
% intermediate functions
\newcommand*\WirePosition[1]{%
  \fpeval{(#1)*\WindingRadius}
}
\newcommand*\WindingsPositionX[1]{%
  \fpeval{(#1-1)*(\CoreThickness+\CoreholeHorizontal)}
}
\newcommand*\LabelPositionX[1]{%
  \fpeval{\CoreThickness/2+\WindingsPositionX{#1}}
}
\newcommand*\LabelPositionY{%
  \fpeval{(\CoreholeVertical+\WirePosition{4*\NumberOfWindingsBottom+2}
           -\WirePosition{4*\NumberOfWindingsTop+2})/2+\CoreThickness}
}
\newcommand*\ComponentStart{%
  \fpeval{3*\CoreThickness+2*\CoreholeHorizontal+\WindingRadius
          +\ElectroamgnetComponentDistance}
}
\newcommand*\ComponentHeight{%
  \fpeval{\CoreThickness+\CoreholeVertical/2-2*\ComponentEndHeight
          -\ComponentsVerticalDistance/2}
}
\newcommand*\ComponentNumber[1]{%
  \fpeval{(#1-1)*(\ComponentsHorizontalDistance+\ComponentThickness)}
}
\newcommand*\ComponentNoteX[1]{%
  \fpeval{\ComponentStart+\ComponentNumber{#1}}
}
% core
\newcommand*\Core{
  % `outer frame'
  \psframe(0,0)%
          (\fpeval{3*\CoreThickness+2*\CoreholeHorizontal},
           \fpeval{2*\CoreThickness+\CoreholeVertical})
  % first hole
  \psframe(\CoreThickness,\CoreThickness)%
          (\fpeval{\CoreThickness+\CoreholeHorizontal},
           \fpeval{\CoreThickness+\CoreholeVertical})
  % second hole
  \psframe(\fpeval{2*\CoreThickness+\CoreholeHorizontal},\CoreThickness)%
          (\fpeval{2*(\CoreThickness+\CoreholeHorizontal)},
           \fpeval{\CoreThickness+\CoreholeVertical})%
}
% single winding
\newcommand*\Loop[1]{%
  \psarc(0,\WirePosition{4*#1-1}){\WindingRadius}{90}{270}
  \psline(0,\WirePosition{4*#1-2})(\CoreThickness,\WirePosition{4*#1-2})
  \psarc(\CoreThickness,\WirePosition{4*#1-3}){\WindingRadius}{270}{90}%
}
% collection of windings
\newcommand*\WireFull[1]{%
  \psline{*-}(-\WireEndLength,\WirePosition{4*#1+2})%
             (\CoreThickness,\WirePosition{4*#1+2})
  \psarc(\CoreThickness,\WirePosition{4*#1+1}){\WindingRadius}{270}{90}
  \multido{\iA = 1+1}{#1}{\Loop{\iA}}
  \psline{-*}(0,0)(-\WireEndLength,0)%
}
% label
\newcommand*\Label[2]{%
\def\displacement{0.2}
\def\LabelSeparation{1pt}
  \uput{\LabelSeparation}[90]%
    (\LabelPositionX{#1},\fpeval{\LabelPositionY+\displacement})%
    {$\Psi_{\scriptscriptstyle \Name{#2}}$}
  \uput{\LabelSeparation}[270]%
    (\LabelPositionX{#1},\LabelPositionY)%
    {\psline{->}(0,\fpeval{-1+\displacement})(0,\displacement)}%
}
% windings and label combined
\newcommand*\Column[2]{%
  % top windings
  \rput(\WindingsPositionX{#1},
        \fpeval{(\CoreThickness+\CoreholeVertical)
                -(\WirePosition{4*\NumberOfWindingsTop+2}
                  +\WindingsCoreCornerDistance)})%
       {\WireFull{\NumberOfWindingsTop}}
  % label
  \Label{#1}{#2}
  % bottom windings
  \rput(\WindingsPositionX{#1},
        \fpeval{\CoreThickness+\WindingsCoreCornerDistance})%
       {\WireFull{\NumberOfWindingsBottom}}%
}
% black component
\newcommand*\BlackComponent[3]{%
  % nodes
  \pnodes%
    (\ComponentNoteX{#1},
     0){P1}%
    (\ComponentNoteX{#1},
     \ComponentEndHeight){P2}%
    (\fpeval{\ComponentStart-\ComponentThickness/2+\ComponentNumber{#1}},
      \ComponentEndHeight){P3}%
    (\fpeval{\ComponentStart+\ComponentThickness/2+\ComponentNumber{#1}},
     \fpeval{\ComponentEndHeight+\ComponentHeight}){P4}%
    (\ComponentNoteX{#1},
     \fpeval{\ComponentEndHeight+\ComponentHeight}){P5}%
    (\ComponentNoteX{#1},
     \fpeval{2*\ComponentEndHeight+\ComponentHeight}){P6}
  % bottom wire
  \psline{*-}(P1)(P2)
  % component
  \psframe[
    fillstyle = solid,
    fillcolor = black
  ](P3)(P4)
  % top wire
  \psline{-*}(P5)(P6)
  % labels
  \uput[20](P1){$#2$}
  \uput[340](P6){$#3$}%
}
% black component, gathered
\newcommand*\Component[3]{%
  \rput(0,\fpeval{1016/7227}){\BlackComponent{#1}{#2}{#3}}
  \rput(0,\fpeval{\CoreThickness+\CoreholeVertical/2
                  +\ComponentsVerticalDistance/2-1016/7227})%
       {\BlackComponent{#1}{\Name{#2}}{\Name{#3}}}%
}


%%% parameters %%%
% core placement
\newcommand*\CoreThickness{2}
\newcommand*\CoreholeHorizontal{5}
\newcommand*\CoreholeVertical{8}
% wire placement
\newcommand*\WindingsCoreCornerDistance{0.5}
\newcommand*\WireEndLength{0.7}
\newcommand*\WindingRadius{0.15}
% number of windings
\newcommand*\NumberOfWindingsTop{2}
\newcommand*\NumberOfWindingsBottom{3}
% electromagnet--components distance
\newcommand*\ElectroamgnetComponentDistance{4}
% black components
\newcommand*\ComponentEndHeight{0.8}
\newcommand*\ComponentThickness{1}
\newcommand*\ComponentsHorizontalDistance{3}
\newcommand*\ComponentsVerticalDistance{2}


\pagestyle{empty}

\begin{document}

\begin{center}
\psset{unit = 0.5}
\begin{pspicture}%
  (\DiagramHorizontalStart,0)%
  (\DiagramHorizontalEnd,\DiagramVerticalEnd)
 %%% electromagnet
  % core
  \Core
  % wires and labels
  \Column{1}{a}
  \Column{2}{b}
  \Column{3}{c}
 %%% components
  \Component{1}{a}{x}
  \Component{2}{b}{y}
  \Component{3}{c}{z}
\end{pspicture}
\end{center}

\end{document}

output

Notice that the drawing is 'automated'; you choose the values of all the parameters yourself and the drawing will be adjusted accordingly.

18

Here you have a starting point.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}

\draw (0,0) rectangle (7,5);
\draw (1,1) rectangle (3,4);
\draw (4,1) rectangle (6,4);

\foreach \i in {0,3,6}{
\begin{scope}[xshift=\i{}cm]
\path[fill] (-0.3,3.5) circle (2pt);
\draw[thick] (-0.3,3.5) -- (1,3.5) arc [start angle=0, delta angle =-180, radius=.5mm, rotate=90];
\draw[thick] (0,3.4) arc [start angle=0, delta angle =180, radius=.5mm, rotate=90] -- (1,3.3) arc [start angle=0, delta angle =-180, radius=.5mm, rotate=90];
\draw[thick] (0,3.2) arc [start angle=0, delta angle =180, radius=.5mm, rotate=90] -- (1.3,3.1);
\path[fill] (1.3,3.1) circle (2pt);
\end{scope}}

\end{tikzpicture}
\end{document}

enter image description here

Update

Just for fun I've thought it was a good example for practising with pics and quotes. You need TiKZ 3.0.0 which is going to CTAN

The new code is:

\documentclass[tikz,border=3mm]{standalone}

\usetikzlibrary{quotes,arrows.meta}

\begin{document}

\tikzset{
    terminal_a/.pic = {%
        \coordinate (-in) at (-3mm,0);
        \coordinate (-out) at (-3mm,-4.5mm);

        \path[fill] (-in) circle (2pt);
        \draw[thick] (-in)--(0,0)--++(0:1cm) arc[start angle=90, delta angle=-180, radius=.75mm]; 
        \draw[thick] (0,-1.5mm) arc[start angle=90, delta angle=180, radius=.75mm]--++(0:1cm) arc[start angle=90, delta angle=-180, radius=.75mm]; 
        \fill (-out) circle (2pt);
        \draw[thick] (-out) -- ++(0:3mm);
        },
    terminal_b/.pic = {%
        \coordinate (-in) at (-3mm,0);
        \coordinate (-out) at (-3mm,-7.5mm);

        \path[fill] (-in) circle (2pt);
        \draw[thick] (-in)--(0,0)--++(0:1cm) arc[start angle=90, delta angle=-180, radius=.75mm]; 
        \draw[thick] (0,-1.5mm) arc[start angle=90, delta angle=180, radius=.75mm]--++(0:1cm) arc[start angle=90, delta angle=-180, radius=.75mm]; 
        \draw[thick] (0,-4.5mm) arc[start angle=90, delta angle=180, radius=.75mm]--++(0:1cm) arc[start angle=90, delta angle=-180, radius=.75mm]; 
        \fill (-out) circle (2pt);
        \draw[thick] (-out) -- ++(0:3mm);
        },
    field/.pic = {
        \draw[thick,-Stealth] (0,0) -- (90:7mm) node[above] {\tikzpictext};
        }
}

\begin{tikzpicture}
\draw (0,0) rectangle (7,5);
\draw (1,1) rectangle (3,4);
\draw (4,1) rectangle (6,4);

\foreach \i/\j in {0/A,3/B,6/C}{
    \pic (upper-\j) at (\i,3.8) {terminal_a};
    \pic (lower-\j) at (\i,2) {terminal_b};
    \pic["$\Psi_\j$"] at ([xshift=5mm]\i,2.2) {field};
    }

\node[left] at (upper-A-in) {A};
\draw[red] (upper-A-out) to [bend right] (lower-A-in);

\end{tikzpicture}
\end{document}

and the result is

enter image description here

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.