On this blog I found a 3D drawing of a transformer by Thomas Söll.
After a few changes, I have the following code:
\documentclass{article}
\usepackage{pst-solides3d}
\usepackage{expl3}
% Parameters.
\def\radius{1.11}
\def\windingsOne{32}
\def\windingsTwo{64}
% If 4 windings are the most, a radius of at least 0,93 is required.
% If 8 windings are the most, a radius of at least 0,95 is required.
% If 16 windings are the most, a radius of at least 0,95 is required.
% If 32 windings are the most, a radius of at least 1,00 is required.
% If 64 windings are the most, a radius of at least 1,11 is required.
% Activating floating point calculation.
\ExplSyntaxOn
\cs_new_eq:NN
\calc
\fp_eval:n
\ExplSyntaxOff
% Constants.
\def\factor{\calc{5*\windingsTwo}}
\def\lengthA{\calc{2*pi*\windingsOne/\factor}}
\def\lengthB{\calc{2/5*pi}}
\def\vertDist{\calc{3/4*pi}}
\def\thickness{\calc{16/(25*\windingsTwo)}}
% Global setup.
\psset{%
viewpoint=20 5 15 rtp2xyz,
lightsrc=20 60 60 rtp2xyz,
Decran=30
}
\psset{%
solidmemory,
algebraic
}
% Objects with predefined options.
\newpsobject{core}{psSolid}{%
object=parallelepiped,
incolor=red,
fillcolor=cyan!50,
grid=false
}
\newpsobject{wire}{psSolid}{
object=courbe,
r=\thickness,
linewidth=0.5pt,
linecolor=red!60,
incolor=red!60,
fillcolor=red!60,
resolution=727,
ngrid=727 30,
action=none
}
\newpsobject{connect}{psSolid}{
object=fusion,
linecolor=gray,
grid=false,
action=draw**
}
\pagestyle{empty}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{pspicture}(-3,-3)(8,8)
% --------------- Core ---------------
\core[a=1,b=5,c=1,action=draw**,name=H1](0,1.5,-0.5)
\core[a=1,b=1,c=3,action=none,name=H2](0,-0.5,1.5)
\core[a=1,b=1,c=3,action=none,name=H3](0,3.5,1.5)
% --------------- Wire ---------------
{\defFunction{helixA}(t){\radius*cos(\factor*t)}{\radius*sin(\factor*t)}{\vertDist*t}
\wire[function=helixA,range=0 \lengthA,name=wire1](0,-0.5,0)}%
{\defFunction{helixB}(t){\radius*cos(\factor*t)}{-\radius*sin(\factor*t)}{\vertDist*t}
\wire[function=helixB,range=0 \lengthB,name=wire2](0,3.5,0)}%
% ------------- Assembly -------------
\connect[base=H2 wire1]
\connect[base=H3 wire2]
\composeSolid
\core[a=1,b=5,c=1,action=draw**,name=H4](0,1.5,3.5)
\end{pspicture}
\end{figure}
\end{document}
My problem is that the values of the constants \factor, \lengthA, \lengthB, \vertDist, and \thickness are found by hand. Can someone tell me what should be precisely if they should be dependant on the number of windings around the transformer core?
P.S. The code takes a long time (circa 1 minute on my computer) to compile, so if someone can teel me how to recure the compile time, please let me know!
Update
Using Herbert's answer, I ended up with the following:
\documentclass{article}
\usepackage{pst-solides3d}
%% Parameters
% Radii
\def\rHelix{1.1}
\def\rWire{0.025}
% #windings = \F*\N<left/right>/2
\def\F{80}
\def\Nleft{0.75 } % max(\Nleft) = 1
\def\Nright{0.25 } % max(\Nright) = 1
%% Colours
\colorlet{wireColor}{red!60}
\colorlet{coreColor}{cyan!50}
%% Wire
\newpsobject{wire}{psSolid}{
object=courbe,
ngrid=970 \Nleft mul cvi 15, % If \Nright > \Nleft, \Nleft should be \Nright
r=\rWire,
fillcolor=wireColor,
incolor=wireColor
}
\pagestyle{empty}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{pspicture}(-5,-5)(5,5)
\psset{
algebraic,
viewpoint=20 5 10 rtp2xyz,
lightsrc=20 60 60 rtp2xyz,
Decran=30,
solidmemory,
action=none,
grid=false
}
%%--------- Core ------------
\psSolid[object=anneau,h=1.0,R=4,r=2.5,ngrid=4,RotZ=90,RotY=45,RotX=90,
fillcolor=coreColor,name=core]
%%--------- Wire ------------
% Left
\defFunction{heliceA}(t){\rHelix*cos(\F*t)}{\rHelix*sin(\F*t)}{t/\Nleft}
\wire[function=heliceA,range=0 Pi \Nleft mul,name=wireA](0,-2.25,-1.5)
% Right
\defFunction{heliceB}(t){\rHelix*cos(\F*t)}{-\rHelix*sin(\F*t)}{t/\Nright}
\wire[function=heliceB,range=0 Pi \Nright mul,name=wireB](0,2.25,-1.5)
%%------- Assembly --------
\psSolid[object=fusion,base=core wireA wireB,action=draw**]
\end{pspicture}
\end{figure}
\end{document}
P.S. I ended up not using what I aksed for in the comments to Herbert's answer.
Update 2
I marginally changed the code in the first update.
Final Version
\documentclass{article}
\usepackage{pst-solides3d}
%% Parameters
% Windings
\def\lWind{60}
\def\rWind{30}
% Radii
\def\rHelix{1.13}
\def\rWire{0.006}
% Constants
\def\factor{160} % \factor > \lWind,\rWind
\pstVerb{%
/left 2 \lWind\space mul \factor\space div def
/right 2 \rWind\space mul \factor\space div def
}
%% Colours
\colorlet{wireColor}{red!60}
\colorlet{coreColor}{cyan!50}
%% Wire
\newpsobject{wire}{psSolid}{%
object=courbe,
% Choose max(left,right)
% The smaller max(left,right), the larger the constant multiplied with it
ngrid=970 left mul cvi 15,
r=\rWire,
fillcolor=wireColor,
incolor=wireColor
}
\pagestyle{empty}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{pspicture}(-5,-5)(5,5)
\psset{%
algebraic,
viewpoint=20 5 10 rtp2xyz,
lightsrc=20 60 60 rtp2xyz,
Decran=30,
solidmemory,
action=none,
grid=false
}
%%--------- Core ----------
\psSolid[object=anneau,h=1.0,R=4,r=2.5,ngrid=4,RotZ=90,RotY=45,RotX=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**]
\end{pspicture}
\end{figure}
\end{document}

