Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the picture of a transformer on the page:

what-I-want

How do I draw this using either TikZ (which I have not used before) or PSTricks?

share|improve this question
1  
You can look at my answer for this question and then you can make an attempt with the gray solid and the green path. After if you have some problems, we can help you for the end of the drawing. –  Alain Matthes Jul 2 '12 at 7:32
    
Yes I forgot :( tex.stackexchange.com/questions/15079/… –  Alain Matthes Jul 2 '12 at 7:59
    
As I said, I have not used TikZ before, but I will give it a try. Thank you. –  Svend Tveskæg Jul 2 '12 at 8:18
    
If you want to learn more about TikZ by seeing some examples I'd suggest giving a shot at TikZ and PGF examples There are many examples there with their source code and the final results –  Vagelis Bebelis Jul 2 '12 at 14:28
    
Welcome to TEX.SX! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  azetina Jul 2 '12 at 14:37

2 Answers 2

up vote 13 down vote accepted

It's quite easy to set up custom axes in TikZ: for instance, x={(0.707,0.707)} means that the x-vector points in direction of 45° (up right) with length 1 (in general : (r cos angle,r sin angle)). I used 45°, 165° and 90° for x, y and z axes. The hard part is imagining what coordinates to use. Another difficulty is the upper part of the left coil: if you draw it via a foreach loop, then some parts are in front of the front face, while some are behind it, so I used a scope to restrict the drawing.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\newcommand{\innercolor}{gray!80!black}
\newcommand{\outercolor}{gray!80!white}
\newcommand{\leftcoil}{red!75!gray}
\newcommand{\rightcoil}{green!75!gray}
\pgfmathsetmacro{\coilseparation}{0.02}

\pgfmathsetmacro{\halflinewidth}{0.008}

\begin{document}

\begin{tikzpicture}[x={(0.707cm,0.707cm)},y={(-0.966cm,0.259cm)},z={(0cm,1cm)}]
    \filldraw[fill=\innercolor]  (0,1,1) -- (1,1,1) -- (1,4,1) -- (0,4,1) -- cycle;
    \filldraw[fill=\innercolor]  (1,4,1) -- (0,4,1) -- (0,4,4) -- (1,4,4) -- cycle;
    \filldraw[fill=\innercolor]  (0,0,0) -- (1,0,0) -- (1,0,5) -- (0,0,5) -- cycle;
    \filldraw[fill=\innercolor]  (0,0,5) -- (0,5,5) -- (1,5,5) -- (1,0,5) -- cycle;
    \filldraw[fill=\outercolor,even odd rule]    (0,0,0) -- (0,5,0) -- (0,5,5) -- (0,0,5) --cycle (0,1,1) -- (0,4,1) -- (0,4,4) -- (0,1,4) --cycle ;
    \begin{scope}
    \clip (0,3,1) -- (0,6,1) -- (0,6,4) -- (0,3,4);
    \foreach \z in {1.125,1.375,...,3.875}
    {   \draw[\leftcoil,thick] (0,5,\z) -- (-\coilseparation,5,\z) -- (-\coilseparation,4-\coilseparation,\z) -- (1+\coilseparation,4-\coilseparation,\z) -- (1+\coilseparation,4,\z);
    }
    \end{scope}
    \foreach \z in {1.25,1.75,...,3.75}
    {   \draw[\rightcoil,thick] (0,1,\z) -- (-\coilseparation,1,\z) -- (-\coilseparation,0-\coilseparation,\z) -- (1+\coilseparation,0-\coilseparation,\z) -- (1+\coilseparation,0,\z);
    }

\end{tikzpicture}

\end{document}

enter image description here


Edit 1: To help you figure out where you are in 3D, you can append this in the tikzpicture:

    \draw[ultra thick,blue,->] (0,0,0) -- (2.5,0,0) node[below right] {x};
\draw[ultra thick,blue,->] (0,0,0) -- (0,6.5,0) node[below] {y};
\draw[ultra thick,blue,->] (0,0,0) -- (0,0,6.5) node[right] {z};
\foreach \x in {1,2}    
{   \draw[ultra thick,blue] (\x,0.1,0) -- (\x,-0.1,0) node[below right] {\x};
}
\foreach \yz in {1,2,3,4,5,6}   
{   \draw[ultra thick,blue] (0.1,\yz,0) -- (-0.1,\yz,0) node[below] {\yz};
    \draw[ultra thick,blue] (0.1,0,\yz) -- (-0.1,0,\yz) node[right] {\yz};
}

enter image description here

share|improve this answer
    
This is awesome. Thank you. Any chance I can get you (or any other) to draw the rest of the picture? I would like to learn TikZ and I think I will do this best by seeing some examples (and read manuals). –  Svend Tveskæg Jul 2 '12 at 10:17
1  
I am still a tikz beginner, but you could browse questions on the site. (I have asked quite a few questions aswell). And then attempt to improve this image. You learn best by trying yourself. =) –  N3buchadnezzar Jul 2 '12 at 14:31
    
@Tom Bombadil: Thank you for adding the axes. I am (very!) slowly going through the example starting on page 40 in the TikZ and PGF manual; I guess I have to follow more basic examples before I can draw the transformer. –  Svend Tveskæg Jul 2 '12 at 16:45

Along time ago I figured out how to do it using PSTricks by modifying the code taken from here:

\documentclass{article}

\usepackage{pst-solides3d}

% Subscript as \textup
\makeatletter
 \begingroup
  \catcode`\_=\active
  \protected\gdef_{\@ifnextchar|\subtextup\sb}
 \endgroup
\def\subtextup|#1|{\sb{\textup{#1}}}
\AtBeginDocument{\catcode`\_=12 \mathcode`\_=32768}
\makeatother

%% Parameters
% Windings
\def\lWind{40 }
\def\rWind{80 }
% Radii
\def\rHelix{1.13}
\def\rWire{0.004}

% Constants
\def\factor{160 } % \factor > \lWind,\rWind
\pstVerb{
  /left  2 \lWind mul \factor div def
  /right 2 \rWind mul \factor div def
}

%% Colors
\colorlet{wireColor}{red!60}
\colorlet{coreColor}{cyan!50}
%% Wire
\newpsobject{wire}{psSolid}{
  object = courbe,
  ngrid = 4365 left mul cvi 5,
  r = \rWire,
  fillcolor = wireColor,
  incolor = wireColor
}

\begin{document}

\psset{
  unit = 0.87
}
\begin{pspicture}(-6.6,-4.4)(6.6,4.2)
\psset{
  algebraic,
  solidmemory,
  viewpoint = 20 5 10 rtp2xyz,
  lightsrc = 20 60 60 rtp2xyz,
  Decran = 30,
  grid = false,
  action = none
}
%%--------- Core ----------
\psSolid[
  object = anneau,
  h = 1.0,
  R = 4,
  r = 2.5,
  ngrid = 4,
  RotX = 90,
  RotY = 45,
  RotZ = 90,
  fillcolor = coreColor,
  name = core
]
%%--------- Wire ----------
% Left
\defFunction{heliceA}(t){\rHelix*cos(\factor*t)}{\rHelix*sin(\factor*t)}{t/left}
\wire[
  function = heliceA,
  range = 0 Pi left mul,
  name = wireA
](0,-2.25,-1.5)
% Right
\defFunction{heliceB}(t){\rHelix*cos(\factor*t)}{-\rHelix*sin(\factor*t)}{t/right}
\wire[
  function = heliceB,
  range = 0 Pi right mul,
  name = wireB
](0,2.25,-1.5)
%%------- Assembly --------
\psSolid[
  object = fusion,
  base = core wireA wireB,
  action = draw**
]
%%---- Connecting wire ----
% Left
\psline[
  linewidth = 1.5pt
](-6.8,2.71)(-3.705,2.71)(-3.705,2.31)
\psline[
  linewidth = 1.5pt
](-6.8,-2.845)(-3.65,-2.845)(-3.65,-2.545)
\pcline[
  linewidth = 0.5pt
]{<->}(-6,2.71)(-6,-2.845)
\ncput*{\small $U_|p|$}
\uput[315](-6,2.71){\small $+$}
\uput[40](-6,-2.845){\small $-$}
\psline{->}(-6.8,3.01)(-5.5,3.01)
\uput[0](-5.5,3.01){\small $I_|p|$}
\rput(-1.3,0){\small $N_|p|$}
% Right
\psline[
  linewidth = 1.5pt
](6.8,2.65)(3.48,2.65)(3.48,2.25)
\psline[
  linewidth = 1.5pt
](6.8,-3.0)(3.41,-3)(3.41,-2.7)
\pcline[
  linewidth = 0.5pt
]{<->}(6,2.65)(6,-3)
\ncput*{\small $U_|s|$}
\uput[225](6,2.65){\small $+$}
\uput[140](6,-3){\small $-$}
\psline{->}(5.5,2.95)(6.8,2.95)
\uput[180](5.5,2.95){\small $I_|s|$}
\rput(1.3,0){\small $N_|s|$}
\end{pspicture}

\end{document}

output

Note that the compilation from PS to PDF takes some seconds.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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