draw a technical instrument geophone
Could you help to draw the geophone?
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
begin{document}
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
tikz-pgf
add a comment |
Could you help to draw the geophone?
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
begin{document}
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
tikz-pgf
1
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
For the ground, you could use some something likedraw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.
– hpekristiansen
Dec 15 '18 at 2:05
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52
add a comment |
Could you help to draw the geophone?
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
begin{document}
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
tikz-pgf
Could you help to draw the geophone?
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
begin{document}
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
tikz-pgf
tikz-pgf
asked Dec 14 '18 at 17:00
Thumbolt
1,327718
1,327718
1
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
For the ground, you could use some something likedraw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.
– hpekristiansen
Dec 15 '18 at 2:05
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52
add a comment |
1
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
For the ground, you could use some something likedraw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.
– hpekristiansen
Dec 15 '18 at 2:05
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52
1
1
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
For the ground, you could use some something like
draw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.– hpekristiansen
Dec 15 '18 at 2:05
For the ground, you could use some something like
draw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.– hpekristiansen
Dec 15 '18 at 2:05
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52
add a comment |
2 Answers
2
active
oldest
votes
I am goin to assume, that the problem is to make the coil wrap around the magnet. The solution is described in this answer: https://tex.stackexchange.com/a/43605/8650 (by me).
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}
makeatletter
% Decorations based on
% https://tex.stackexchange.com/questions/32297/modify-tikz-coil-decoration/43605#43605
% coilup decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coilup}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{-1 }{9}}
pgfpathcurveto
{pgfpoint@oncoil{0.445}{-1 }{10}}
{pgfpoint@oncoil{0 }{-0.555}{11}}
{pgfpoint@oncoil{0 }{ 0 }{12}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
% Uncomment the following lines to close the last loop
% pgfpathcurveto
% {pgfpoint@oncoil{1.555}{ 1 }{4}}
% {pgfpoint@oncoil{2 }{ 0.555}{5}}
% {pgfpoint@oncoil{2 }{ 0 }{6}}
% pgfpathcurveto
% {pgfpoint@oncoil{2 }{-0.555}{7}}
% {pgfpoint@oncoil{1.555}{-1 }{8}}
% {pgfpoint@oncoil{0 }{-1 }{9}}
}
state{final}
{
pgfpathmoveto{pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coildown}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathmoveto{pgfpoint@oncoil{1 }{1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
pgfpathcurveto
{pgfpoint@oncoil{2 }{-0.555}{7}}
{pgfpoint@oncoil{1.555}{-1 }{8}}
{pgfpoint@oncoil{1 }{-1 }{9}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
% Comment the next 5 lines when closing the last loop
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
}
state{final}
{}
}
defpgfpoint@oncoil#1#2#3{%
pgf@x=#1pgfdecorationsegmentamplitude%
pgf@x=pgfdecorationsegmentaspectpgf@x%
pgf@y=#2pgfdecorationsegmentamplitude%
pgf@xa=0.083333333333pgfdecorationsegmentlength%
advancepgf@x by#3pgf@xa%
}
makeatother
begin{document}
begin{tikzpicture}
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coilup},decorate] (-0.2,-1) -- (-0.2,-2);
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
Notice that everything between makeatletter
and makeatother
is just to make coilup
and coildown
work. The rest is not more complicated than your own code.
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!-0.2
indraw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
add a comment |
Here is a proposal with some more explanations and an animation below. Most of the elements are in except for the vertical lines from the terminal to the spiral. This is because I do not understand them, i.e. don't know if these are elements of a 3d picture or just some vertical lines.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d,decorations.pathmorphing}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
tdplotsetmaincoords{70}{60} % the first argument cannot be larger than 90
begin{tikzpicture}[font=sffamily]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
%
% lower spiral
draw (0,0,-4) coordinate (bottom) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-31)});
foreach Y in {-30,-29,...,-20}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-19)})
-- (0,0,-cubez/2);
% big spiral in the back
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% cube
foreach X in {3,6,2}
{DrawSinglePlane{X}}
begin{scope}[canvas is yz plane at x=cubex/2]
coordinate (plane) at (0,-0.4*cubez);
end{scope}
% big spiral in the front
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% upper spiral
draw (0,0,cubez/2) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+19)});
foreach Y in {20,21,...,30}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+31)})
-- (0,0,4) coordinate (top);
% coords
path ({0.2*R*cos(tdplotmainphi+180)},{0.2*R*sin(tdplotmainphi+180)},{2.5})
coordinate (spring)
({R*cos(tdplotmainphi+230)},{R*sin(tdplotmainphi+230)},{0.1*230/360}) coordinate (coil)
({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},{0}) coordinate (right)
({R*cos(tdplotmainphi+180)},{R*sin(tdplotmainphi+180)},{0}) coordinate (left);
end{scope}
draw (left |- bottom) rectangle (right |- top);
path (top -| left) -- (top -| right) node[fill,inner sep=3pt,above=0pt,pos=0.2] (L){}
node[fill,inner sep=3pt,above=0pt,pos=0.8] (R){};
draw (L) -- ++ (0,1) -| node[circle,draw,pos=0.25,fill=white]{A} (R);
draw (spring) -- ++ (-2.5,0) node[left](spring) {spring};
draw (coil) -- ++ (-2.5,0);
node[anchor=west,fill=white] at (spring.west |- coil) {coil};
draw (R) -- ++ (1.5,0) node[right] (terminal) {terminal};
begin{scope}
clip[rounded corners]
([xshift=-2.8cm]bottom -| left) -- ([xshift=2.8cm]bottom -| right)
|- ++ (-2,-2) -| cycle;
draw[fill=gray!30,decoration={random steps,segment length=2mm}]
([xshift=-3cm,yshift=-4mm]bottom -| left) [decorate]-- ([xshift=3cm,yshift=-4mm]bottom -|
right) |- ++ (-2,-2) -| cycle;
end{scope}
path (bottom -| left) -- (bottom -| right)
coordinate[midway,yshift=-1cm] (aux0)
coordinate[midway,yshift=-1.7cm] (aux1)
coordinate[pos=0.4,yshift=-2mm] (aux2)
coordinate[pos=0.6,yshift=-2mm] (aux3);
draw[fill=gray] (bottom -| left) |- (aux2)
-- (aux1) -- (aux3) -| (bottom -| right);
draw (aux0) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- aux0) {spike in\
ground};
draw (plane) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- plane)
{oscillating\ magnet};
end{tikzpicture}
end{document}
This is just for fun. In principle you could employ pgfplots for that. I focus on the cube and the spiral.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=8cm}
begin{document}
begin{tikzpicture}[declare function={spiralz(x,y)=x/360+y;}]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{2}
begin{axis}[hide axis,view={40}{35},set layers,
cube/size x=cubex cm,cube/size y=cubey cm,cube/size z=cubez cm]
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain=pgfkeysvalueof{/pgfplots/view/az}:{pgfkeysvalueof{/pgfplots/view/az}+180},mesh,point meta=x,color=black,
on layer=axis background] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
addplot3 [only marks,mark=cube*,mark size=7,
on layer=pre main,color=yellow] coordinates {(0,0,10)};
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain={pgfkeysvalueof{/pgfplots/view/az}+180}:{pgfkeysvalueof{/pgfplots/view/az}+360},mesh,point meta=x,color=black,
on layer=axis foreground] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
%typeout{pgfkeysvalueof{/pgfplots/view/az},pgfkeysvalueof{/pgfplots/view/el}}
end{axis}
end{tikzpicture}
end{document}
The advantage of this is that you have orthographic projections and can adjust the view. The disadvantage is the compilation time.
In order to speed up, one can use tikz-3dplot
, which requires to distinguish 4 cases (in this animation).
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
foreach X in {0,5,...,355}
{tdplotsetmaincoords{90-40*sin(X)}{X} % the first argument cannot be larger than 90
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
path[use as bounding box] (-2*R,-2.4*R) rectangle (2*R,2.4*R);
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
ifnumzproj=1
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
ifnumzproj=1
ifnumxproj=1
foreach XX in {2,3,6}
{DrawSinglePlane{XX}}
else
foreach XX in {4,6,2}
{DrawSinglePlane{XX}}
fi
else
ifnumxproj=1
foreach XX in {2,4,6}
{DrawSinglePlane{XX}}
else
foreach XX in {3,6,2}
{DrawSinglePlane{XX}}
fi
fi
ifnumzproj=1
foreach Y in {-5,...,5}
{foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
end{scope}
end{tikzpicture}}
end{document}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464864%2fdraw-a-technical-instrument-geophone%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am goin to assume, that the problem is to make the coil wrap around the magnet. The solution is described in this answer: https://tex.stackexchange.com/a/43605/8650 (by me).
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}
makeatletter
% Decorations based on
% https://tex.stackexchange.com/questions/32297/modify-tikz-coil-decoration/43605#43605
% coilup decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coilup}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{-1 }{9}}
pgfpathcurveto
{pgfpoint@oncoil{0.445}{-1 }{10}}
{pgfpoint@oncoil{0 }{-0.555}{11}}
{pgfpoint@oncoil{0 }{ 0 }{12}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
% Uncomment the following lines to close the last loop
% pgfpathcurveto
% {pgfpoint@oncoil{1.555}{ 1 }{4}}
% {pgfpoint@oncoil{2 }{ 0.555}{5}}
% {pgfpoint@oncoil{2 }{ 0 }{6}}
% pgfpathcurveto
% {pgfpoint@oncoil{2 }{-0.555}{7}}
% {pgfpoint@oncoil{1.555}{-1 }{8}}
% {pgfpoint@oncoil{0 }{-1 }{9}}
}
state{final}
{
pgfpathmoveto{pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coildown}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathmoveto{pgfpoint@oncoil{1 }{1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
pgfpathcurveto
{pgfpoint@oncoil{2 }{-0.555}{7}}
{pgfpoint@oncoil{1.555}{-1 }{8}}
{pgfpoint@oncoil{1 }{-1 }{9}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
% Comment the next 5 lines when closing the last loop
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
}
state{final}
{}
}
defpgfpoint@oncoil#1#2#3{%
pgf@x=#1pgfdecorationsegmentamplitude%
pgf@x=pgfdecorationsegmentaspectpgf@x%
pgf@y=#2pgfdecorationsegmentamplitude%
pgf@xa=0.083333333333pgfdecorationsegmentlength%
advancepgf@x by#3pgf@xa%
}
makeatother
begin{document}
begin{tikzpicture}
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coilup},decorate] (-0.2,-1) -- (-0.2,-2);
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
Notice that everything between makeatletter
and makeatother
is just to make coilup
and coildown
work. The rest is not more complicated than your own code.
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!-0.2
indraw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
add a comment |
I am goin to assume, that the problem is to make the coil wrap around the magnet. The solution is described in this answer: https://tex.stackexchange.com/a/43605/8650 (by me).
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}
makeatletter
% Decorations based on
% https://tex.stackexchange.com/questions/32297/modify-tikz-coil-decoration/43605#43605
% coilup decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coilup}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{-1 }{9}}
pgfpathcurveto
{pgfpoint@oncoil{0.445}{-1 }{10}}
{pgfpoint@oncoil{0 }{-0.555}{11}}
{pgfpoint@oncoil{0 }{ 0 }{12}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
% Uncomment the following lines to close the last loop
% pgfpathcurveto
% {pgfpoint@oncoil{1.555}{ 1 }{4}}
% {pgfpoint@oncoil{2 }{ 0.555}{5}}
% {pgfpoint@oncoil{2 }{ 0 }{6}}
% pgfpathcurveto
% {pgfpoint@oncoil{2 }{-0.555}{7}}
% {pgfpoint@oncoil{1.555}{-1 }{8}}
% {pgfpoint@oncoil{0 }{-1 }{9}}
}
state{final}
{
pgfpathmoveto{pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coildown}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathmoveto{pgfpoint@oncoil{1 }{1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
pgfpathcurveto
{pgfpoint@oncoil{2 }{-0.555}{7}}
{pgfpoint@oncoil{1.555}{-1 }{8}}
{pgfpoint@oncoil{1 }{-1 }{9}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
% Comment the next 5 lines when closing the last loop
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
}
state{final}
{}
}
defpgfpoint@oncoil#1#2#3{%
pgf@x=#1pgfdecorationsegmentamplitude%
pgf@x=pgfdecorationsegmentaspectpgf@x%
pgf@y=#2pgfdecorationsegmentamplitude%
pgf@xa=0.083333333333pgfdecorationsegmentlength%
advancepgf@x by#3pgf@xa%
}
makeatother
begin{document}
begin{tikzpicture}
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coilup},decorate] (-0.2,-1) -- (-0.2,-2);
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
Notice that everything between makeatletter
and makeatother
is just to make coilup
and coildown
work. The rest is not more complicated than your own code.
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!-0.2
indraw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
add a comment |
I am goin to assume, that the problem is to make the coil wrap around the magnet. The solution is described in this answer: https://tex.stackexchange.com/a/43605/8650 (by me).
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}
makeatletter
% Decorations based on
% https://tex.stackexchange.com/questions/32297/modify-tikz-coil-decoration/43605#43605
% coilup decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coilup}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{-1 }{9}}
pgfpathcurveto
{pgfpoint@oncoil{0.445}{-1 }{10}}
{pgfpoint@oncoil{0 }{-0.555}{11}}
{pgfpoint@oncoil{0 }{ 0 }{12}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
% Uncomment the following lines to close the last loop
% pgfpathcurveto
% {pgfpoint@oncoil{1.555}{ 1 }{4}}
% {pgfpoint@oncoil{2 }{ 0.555}{5}}
% {pgfpoint@oncoil{2 }{ 0 }{6}}
% pgfpathcurveto
% {pgfpoint@oncoil{2 }{-0.555}{7}}
% {pgfpoint@oncoil{1.555}{-1 }{8}}
% {pgfpoint@oncoil{0 }{-1 }{9}}
}
state{final}
{
pgfpathmoveto{pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coildown}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathmoveto{pgfpoint@oncoil{1 }{1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
pgfpathcurveto
{pgfpoint@oncoil{2 }{-0.555}{7}}
{pgfpoint@oncoil{1.555}{-1 }{8}}
{pgfpoint@oncoil{1 }{-1 }{9}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
% Comment the next 5 lines when closing the last loop
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
}
state{final}
{}
}
defpgfpoint@oncoil#1#2#3{%
pgf@x=#1pgfdecorationsegmentamplitude%
pgf@x=pgfdecorationsegmentaspectpgf@x%
pgf@y=#2pgfdecorationsegmentamplitude%
pgf@xa=0.083333333333pgfdecorationsegmentlength%
advancepgf@x by#3pgf@xa%
}
makeatother
begin{document}
begin{tikzpicture}
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coilup},decorate] (-0.2,-1) -- (-0.2,-2);
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
Notice that everything between makeatletter
and makeatother
is just to make coilup
and coildown
work. The rest is not more complicated than your own code.
I am goin to assume, that the problem is to make the coil wrap around the magnet. The solution is described in this answer: https://tex.stackexchange.com/a/43605/8650 (by me).
documentclass[border=5mm,tikz]{standalone}
usetikzlibrary{decorations.pathmorphing,patterns}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}
makeatletter
% Decorations based on
% https://tex.stackexchange.com/questions/32297/modify-tikz-coil-decoration/43605#43605
% coilup decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coilup}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{-1 }{9}}
pgfpathcurveto
{pgfpoint@oncoil{0.445}{-1 }{10}}
{pgfpoint@oncoil{0 }{-0.555}{11}}
{pgfpoint@oncoil{0 }{ 0 }{12}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
pgfpathcurveto
{pgfpoint@oncoil{0 }{ 0.555}{1}}
{pgfpoint@oncoil{0.445}{ 1 }{2}}
{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
% Uncomment the following lines to close the last loop
% pgfpathcurveto
% {pgfpoint@oncoil{1.555}{ 1 }{4}}
% {pgfpoint@oncoil{2 }{ 0.555}{5}}
% {pgfpoint@oncoil{2 }{ 0 }{6}}
% pgfpathcurveto
% {pgfpoint@oncoil{2 }{-0.555}{7}}
% {pgfpoint@oncoil{1.555}{-1 }{8}}
% {pgfpoint@oncoil{0 }{-1 }{9}}
}
state{final}
{
pgfpathmoveto{pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: pgfdecorationsegmentamplitude, pgfdecorationsegmentlength,
pgfdeclaredecoration{coildown}{coil}
{
state{coil}[switch if less than=%
1.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude to last,
width=+pgfdecorationsegmentlength]
{
pgfpathmoveto{pgfpoint@oncoil{1 }{1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
pgfpathcurveto
{pgfpoint@oncoil{2 }{-0.555}{7}}
{pgfpoint@oncoil{1.555}{-1 }{8}}
{pgfpoint@oncoil{1 }{-1 }{9}}
}
state{last}[width=.5pgfdecorationsegmentlength+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude+%
pgfdecorationsegmentaspectpgfdecorationsegmentamplitude,next state=final]
{
% Comment the next 5 lines when closing the last loop
pgfpathmoveto{pgfpoint@oncoil{1 }{ 1 }{3}}
pgfpathcurveto
{pgfpoint@oncoil{1.555}{ 1 }{4}}
{pgfpoint@oncoil{2 }{ 0.555}{5}}
{pgfpoint@oncoil{2 }{ 0 }{6}}
}
state{final}
{}
}
defpgfpoint@oncoil#1#2#3{%
pgf@x=#1pgfdecorationsegmentamplitude%
pgf@x=pgfdecorationsegmentaspectpgf@x%
pgf@y=#2pgfdecorationsegmentamplitude%
pgf@xa=0.083333333333pgfdecorationsegmentlength%
advancepgf@x by#3pgf@xa%
}
makeatother
begin{document}
begin{tikzpicture}
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coilup},decorate] (-0.2,-1) -- (-0.2,-2);
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{3}
pgfmathsetmacro{cubez}{.71}
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,-cubey,0) -- ++(cubex,0,0) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(0,0,-cubez) -- ++(0,-cubey,0) -- ++(0,0,cubez) -- cycle;
draw[red,fill=yellow] (0,0,0) -- ++(-cubex,0,0) -- ++(0,0,-cubez) -- ++(cubex,0,0) -- cycle;
draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,1.52) -- (-.35,0.4);
draw(-.35,1.52)--(-.35,1.8);
draw(-.35,.18)--(-.35,.4);
draw[decoration={aspect=.3523, segment length=.6060285mm, amplitude=1.616mm,coil},decorate] (-.35,-3.52) -- (-.35,-4.4);
draw(-.35,-3.52)--(-.35,-3);
draw(-.35,-4.4)--(-.35,-4.654);
end{tikzpicture}
end{document}
Notice that everything between makeatletter
and makeatother
is just to make coilup
and coildown
work. The rest is not more complicated than your own code.
edited Dec 15 '18 at 2:12
answered Dec 14 '18 at 18:09
hpekristiansen
5,16862864
5,16862864
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!-0.2
indraw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
add a comment |
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!-0.2
indraw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
How can I move the coill to the left slightly so that the magnet is in the center?
– Thumbolt
Dec 15 '18 at 2:06
@Thumbolt: Change the x values!
-0.2
in draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
@Thumbolt: Change the x values!
-0.2
in draw[decoration={aspect=0.1, segment length=2, amplitude=20 mm, coildown},decorate] (-0.2,-1) -- (-0.2,-2);
– hpekristiansen
Dec 15 '18 at 2:09
add a comment |
Here is a proposal with some more explanations and an animation below. Most of the elements are in except for the vertical lines from the terminal to the spiral. This is because I do not understand them, i.e. don't know if these are elements of a 3d picture or just some vertical lines.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d,decorations.pathmorphing}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
tdplotsetmaincoords{70}{60} % the first argument cannot be larger than 90
begin{tikzpicture}[font=sffamily]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
%
% lower spiral
draw (0,0,-4) coordinate (bottom) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-31)});
foreach Y in {-30,-29,...,-20}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-19)})
-- (0,0,-cubez/2);
% big spiral in the back
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% cube
foreach X in {3,6,2}
{DrawSinglePlane{X}}
begin{scope}[canvas is yz plane at x=cubex/2]
coordinate (plane) at (0,-0.4*cubez);
end{scope}
% big spiral in the front
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% upper spiral
draw (0,0,cubez/2) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+19)});
foreach Y in {20,21,...,30}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+31)})
-- (0,0,4) coordinate (top);
% coords
path ({0.2*R*cos(tdplotmainphi+180)},{0.2*R*sin(tdplotmainphi+180)},{2.5})
coordinate (spring)
({R*cos(tdplotmainphi+230)},{R*sin(tdplotmainphi+230)},{0.1*230/360}) coordinate (coil)
({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},{0}) coordinate (right)
({R*cos(tdplotmainphi+180)},{R*sin(tdplotmainphi+180)},{0}) coordinate (left);
end{scope}
draw (left |- bottom) rectangle (right |- top);
path (top -| left) -- (top -| right) node[fill,inner sep=3pt,above=0pt,pos=0.2] (L){}
node[fill,inner sep=3pt,above=0pt,pos=0.8] (R){};
draw (L) -- ++ (0,1) -| node[circle,draw,pos=0.25,fill=white]{A} (R);
draw (spring) -- ++ (-2.5,0) node[left](spring) {spring};
draw (coil) -- ++ (-2.5,0);
node[anchor=west,fill=white] at (spring.west |- coil) {coil};
draw (R) -- ++ (1.5,0) node[right] (terminal) {terminal};
begin{scope}
clip[rounded corners]
([xshift=-2.8cm]bottom -| left) -- ([xshift=2.8cm]bottom -| right)
|- ++ (-2,-2) -| cycle;
draw[fill=gray!30,decoration={random steps,segment length=2mm}]
([xshift=-3cm,yshift=-4mm]bottom -| left) [decorate]-- ([xshift=3cm,yshift=-4mm]bottom -|
right) |- ++ (-2,-2) -| cycle;
end{scope}
path (bottom -| left) -- (bottom -| right)
coordinate[midway,yshift=-1cm] (aux0)
coordinate[midway,yshift=-1.7cm] (aux1)
coordinate[pos=0.4,yshift=-2mm] (aux2)
coordinate[pos=0.6,yshift=-2mm] (aux3);
draw[fill=gray] (bottom -| left) |- (aux2)
-- (aux1) -- (aux3) -| (bottom -| right);
draw (aux0) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- aux0) {spike in\
ground};
draw (plane) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- plane)
{oscillating\ magnet};
end{tikzpicture}
end{document}
This is just for fun. In principle you could employ pgfplots for that. I focus on the cube and the spiral.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=8cm}
begin{document}
begin{tikzpicture}[declare function={spiralz(x,y)=x/360+y;}]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{2}
begin{axis}[hide axis,view={40}{35},set layers,
cube/size x=cubex cm,cube/size y=cubey cm,cube/size z=cubez cm]
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain=pgfkeysvalueof{/pgfplots/view/az}:{pgfkeysvalueof{/pgfplots/view/az}+180},mesh,point meta=x,color=black,
on layer=axis background] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
addplot3 [only marks,mark=cube*,mark size=7,
on layer=pre main,color=yellow] coordinates {(0,0,10)};
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain={pgfkeysvalueof{/pgfplots/view/az}+180}:{pgfkeysvalueof{/pgfplots/view/az}+360},mesh,point meta=x,color=black,
on layer=axis foreground] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
%typeout{pgfkeysvalueof{/pgfplots/view/az},pgfkeysvalueof{/pgfplots/view/el}}
end{axis}
end{tikzpicture}
end{document}
The advantage of this is that you have orthographic projections and can adjust the view. The disadvantage is the compilation time.
In order to speed up, one can use tikz-3dplot
, which requires to distinguish 4 cases (in this animation).
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
foreach X in {0,5,...,355}
{tdplotsetmaincoords{90-40*sin(X)}{X} % the first argument cannot be larger than 90
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
path[use as bounding box] (-2*R,-2.4*R) rectangle (2*R,2.4*R);
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
ifnumzproj=1
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
ifnumzproj=1
ifnumxproj=1
foreach XX in {2,3,6}
{DrawSinglePlane{XX}}
else
foreach XX in {4,6,2}
{DrawSinglePlane{XX}}
fi
else
ifnumxproj=1
foreach XX in {2,4,6}
{DrawSinglePlane{XX}}
else
foreach XX in {3,6,2}
{DrawSinglePlane{XX}}
fi
fi
ifnumzproj=1
foreach Y in {-5,...,5}
{foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
end{scope}
end{tikzpicture}}
end{document}
add a comment |
Here is a proposal with some more explanations and an animation below. Most of the elements are in except for the vertical lines from the terminal to the spiral. This is because I do not understand them, i.e. don't know if these are elements of a 3d picture or just some vertical lines.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d,decorations.pathmorphing}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
tdplotsetmaincoords{70}{60} % the first argument cannot be larger than 90
begin{tikzpicture}[font=sffamily]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
%
% lower spiral
draw (0,0,-4) coordinate (bottom) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-31)});
foreach Y in {-30,-29,...,-20}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-19)})
-- (0,0,-cubez/2);
% big spiral in the back
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% cube
foreach X in {3,6,2}
{DrawSinglePlane{X}}
begin{scope}[canvas is yz plane at x=cubex/2]
coordinate (plane) at (0,-0.4*cubez);
end{scope}
% big spiral in the front
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% upper spiral
draw (0,0,cubez/2) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+19)});
foreach Y in {20,21,...,30}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+31)})
-- (0,0,4) coordinate (top);
% coords
path ({0.2*R*cos(tdplotmainphi+180)},{0.2*R*sin(tdplotmainphi+180)},{2.5})
coordinate (spring)
({R*cos(tdplotmainphi+230)},{R*sin(tdplotmainphi+230)},{0.1*230/360}) coordinate (coil)
({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},{0}) coordinate (right)
({R*cos(tdplotmainphi+180)},{R*sin(tdplotmainphi+180)},{0}) coordinate (left);
end{scope}
draw (left |- bottom) rectangle (right |- top);
path (top -| left) -- (top -| right) node[fill,inner sep=3pt,above=0pt,pos=0.2] (L){}
node[fill,inner sep=3pt,above=0pt,pos=0.8] (R){};
draw (L) -- ++ (0,1) -| node[circle,draw,pos=0.25,fill=white]{A} (R);
draw (spring) -- ++ (-2.5,0) node[left](spring) {spring};
draw (coil) -- ++ (-2.5,0);
node[anchor=west,fill=white] at (spring.west |- coil) {coil};
draw (R) -- ++ (1.5,0) node[right] (terminal) {terminal};
begin{scope}
clip[rounded corners]
([xshift=-2.8cm]bottom -| left) -- ([xshift=2.8cm]bottom -| right)
|- ++ (-2,-2) -| cycle;
draw[fill=gray!30,decoration={random steps,segment length=2mm}]
([xshift=-3cm,yshift=-4mm]bottom -| left) [decorate]-- ([xshift=3cm,yshift=-4mm]bottom -|
right) |- ++ (-2,-2) -| cycle;
end{scope}
path (bottom -| left) -- (bottom -| right)
coordinate[midway,yshift=-1cm] (aux0)
coordinate[midway,yshift=-1.7cm] (aux1)
coordinate[pos=0.4,yshift=-2mm] (aux2)
coordinate[pos=0.6,yshift=-2mm] (aux3);
draw[fill=gray] (bottom -| left) |- (aux2)
-- (aux1) -- (aux3) -| (bottom -| right);
draw (aux0) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- aux0) {spike in\
ground};
draw (plane) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- plane)
{oscillating\ magnet};
end{tikzpicture}
end{document}
This is just for fun. In principle you could employ pgfplots for that. I focus on the cube and the spiral.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=8cm}
begin{document}
begin{tikzpicture}[declare function={spiralz(x,y)=x/360+y;}]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{2}
begin{axis}[hide axis,view={40}{35},set layers,
cube/size x=cubex cm,cube/size y=cubey cm,cube/size z=cubez cm]
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain=pgfkeysvalueof{/pgfplots/view/az}:{pgfkeysvalueof{/pgfplots/view/az}+180},mesh,point meta=x,color=black,
on layer=axis background] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
addplot3 [only marks,mark=cube*,mark size=7,
on layer=pre main,color=yellow] coordinates {(0,0,10)};
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain={pgfkeysvalueof{/pgfplots/view/az}+180}:{pgfkeysvalueof{/pgfplots/view/az}+360},mesh,point meta=x,color=black,
on layer=axis foreground] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
%typeout{pgfkeysvalueof{/pgfplots/view/az},pgfkeysvalueof{/pgfplots/view/el}}
end{axis}
end{tikzpicture}
end{document}
The advantage of this is that you have orthographic projections and can adjust the view. The disadvantage is the compilation time.
In order to speed up, one can use tikz-3dplot
, which requires to distinguish 4 cases (in this animation).
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
foreach X in {0,5,...,355}
{tdplotsetmaincoords{90-40*sin(X)}{X} % the first argument cannot be larger than 90
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
path[use as bounding box] (-2*R,-2.4*R) rectangle (2*R,2.4*R);
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
ifnumzproj=1
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
ifnumzproj=1
ifnumxproj=1
foreach XX in {2,3,6}
{DrawSinglePlane{XX}}
else
foreach XX in {4,6,2}
{DrawSinglePlane{XX}}
fi
else
ifnumxproj=1
foreach XX in {2,4,6}
{DrawSinglePlane{XX}}
else
foreach XX in {3,6,2}
{DrawSinglePlane{XX}}
fi
fi
ifnumzproj=1
foreach Y in {-5,...,5}
{foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
end{scope}
end{tikzpicture}}
end{document}
add a comment |
Here is a proposal with some more explanations and an animation below. Most of the elements are in except for the vertical lines from the terminal to the spiral. This is because I do not understand them, i.e. don't know if these are elements of a 3d picture or just some vertical lines.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d,decorations.pathmorphing}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
tdplotsetmaincoords{70}{60} % the first argument cannot be larger than 90
begin{tikzpicture}[font=sffamily]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
%
% lower spiral
draw (0,0,-4) coordinate (bottom) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-31)});
foreach Y in {-30,-29,...,-20}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-19)})
-- (0,0,-cubez/2);
% big spiral in the back
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% cube
foreach X in {3,6,2}
{DrawSinglePlane{X}}
begin{scope}[canvas is yz plane at x=cubex/2]
coordinate (plane) at (0,-0.4*cubez);
end{scope}
% big spiral in the front
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% upper spiral
draw (0,0,cubez/2) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+19)});
foreach Y in {20,21,...,30}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+31)})
-- (0,0,4) coordinate (top);
% coords
path ({0.2*R*cos(tdplotmainphi+180)},{0.2*R*sin(tdplotmainphi+180)},{2.5})
coordinate (spring)
({R*cos(tdplotmainphi+230)},{R*sin(tdplotmainphi+230)},{0.1*230/360}) coordinate (coil)
({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},{0}) coordinate (right)
({R*cos(tdplotmainphi+180)},{R*sin(tdplotmainphi+180)},{0}) coordinate (left);
end{scope}
draw (left |- bottom) rectangle (right |- top);
path (top -| left) -- (top -| right) node[fill,inner sep=3pt,above=0pt,pos=0.2] (L){}
node[fill,inner sep=3pt,above=0pt,pos=0.8] (R){};
draw (L) -- ++ (0,1) -| node[circle,draw,pos=0.25,fill=white]{A} (R);
draw (spring) -- ++ (-2.5,0) node[left](spring) {spring};
draw (coil) -- ++ (-2.5,0);
node[anchor=west,fill=white] at (spring.west |- coil) {coil};
draw (R) -- ++ (1.5,0) node[right] (terminal) {terminal};
begin{scope}
clip[rounded corners]
([xshift=-2.8cm]bottom -| left) -- ([xshift=2.8cm]bottom -| right)
|- ++ (-2,-2) -| cycle;
draw[fill=gray!30,decoration={random steps,segment length=2mm}]
([xshift=-3cm,yshift=-4mm]bottom -| left) [decorate]-- ([xshift=3cm,yshift=-4mm]bottom -|
right) |- ++ (-2,-2) -| cycle;
end{scope}
path (bottom -| left) -- (bottom -| right)
coordinate[midway,yshift=-1cm] (aux0)
coordinate[midway,yshift=-1.7cm] (aux1)
coordinate[pos=0.4,yshift=-2mm] (aux2)
coordinate[pos=0.6,yshift=-2mm] (aux3);
draw[fill=gray] (bottom -| left) |- (aux2)
-- (aux1) -- (aux3) -| (bottom -| right);
draw (aux0) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- aux0) {spike in\
ground};
draw (plane) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- plane)
{oscillating\ magnet};
end{tikzpicture}
end{document}
This is just for fun. In principle you could employ pgfplots for that. I focus on the cube and the spiral.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=8cm}
begin{document}
begin{tikzpicture}[declare function={spiralz(x,y)=x/360+y;}]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{2}
begin{axis}[hide axis,view={40}{35},set layers,
cube/size x=cubex cm,cube/size y=cubey cm,cube/size z=cubez cm]
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain=pgfkeysvalueof{/pgfplots/view/az}:{pgfkeysvalueof{/pgfplots/view/az}+180},mesh,point meta=x,color=black,
on layer=axis background] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
addplot3 [only marks,mark=cube*,mark size=7,
on layer=pre main,color=yellow] coordinates {(0,0,10)};
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain={pgfkeysvalueof{/pgfplots/view/az}+180}:{pgfkeysvalueof{/pgfplots/view/az}+360},mesh,point meta=x,color=black,
on layer=axis foreground] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
%typeout{pgfkeysvalueof{/pgfplots/view/az},pgfkeysvalueof{/pgfplots/view/el}}
end{axis}
end{tikzpicture}
end{document}
The advantage of this is that you have orthographic projections and can adjust the view. The disadvantage is the compilation time.
In order to speed up, one can use tikz-3dplot
, which requires to distinguish 4 cases (in this animation).
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
foreach X in {0,5,...,355}
{tdplotsetmaincoords{90-40*sin(X)}{X} % the first argument cannot be larger than 90
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
path[use as bounding box] (-2*R,-2.4*R) rectangle (2*R,2.4*R);
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
ifnumzproj=1
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
ifnumzproj=1
ifnumxproj=1
foreach XX in {2,3,6}
{DrawSinglePlane{XX}}
else
foreach XX in {4,6,2}
{DrawSinglePlane{XX}}
fi
else
ifnumxproj=1
foreach XX in {2,4,6}
{DrawSinglePlane{XX}}
else
foreach XX in {3,6,2}
{DrawSinglePlane{XX}}
fi
fi
ifnumzproj=1
foreach Y in {-5,...,5}
{foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
end{scope}
end{tikzpicture}}
end{document}
Here is a proposal with some more explanations and an animation below. Most of the elements are in except for the vertical lines from the terminal to the spiral. This is because I do not understand them, i.e. don't know if these are elements of a 3d picture or just some vertical lines.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d,decorations.pathmorphing}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
tdplotsetmaincoords{70}{60} % the first argument cannot be larger than 90
begin{tikzpicture}[font=sffamily]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
%
% lower spiral
draw (0,0,-4) coordinate (bottom) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-31)});
foreach Y in {-30,-29,...,-20}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360-19)})
-- (0,0,-cubez/2);
% big spiral in the back
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% cube
foreach X in {3,6,2}
{DrawSinglePlane{X}}
begin{scope}[canvas is yz plane at x=cubex/2]
coordinate (plane) at (0,-0.4*cubez);
end{scope}
% big spiral in the front
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
% upper spiral
draw (0,0,cubez/2) -- plot[variable=x,domain=tdplotmainphi+270:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+19)});
foreach Y in {20,21,...,30}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+360]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+Y)});}
draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+90]
({0.2*R*cos(x)},{0.2*R*sin(x)},{0.1*(x/360+31)})
-- (0,0,4) coordinate (top);
% coords
path ({0.2*R*cos(tdplotmainphi+180)},{0.2*R*sin(tdplotmainphi+180)},{2.5})
coordinate (spring)
({R*cos(tdplotmainphi+230)},{R*sin(tdplotmainphi+230)},{0.1*230/360}) coordinate (coil)
({R*cos(tdplotmainphi)},{R*sin(tdplotmainphi)},{0}) coordinate (right)
({R*cos(tdplotmainphi+180)},{R*sin(tdplotmainphi+180)},{0}) coordinate (left);
end{scope}
draw (left |- bottom) rectangle (right |- top);
path (top -| left) -- (top -| right) node[fill,inner sep=3pt,above=0pt,pos=0.2] (L){}
node[fill,inner sep=3pt,above=0pt,pos=0.8] (R){};
draw (L) -- ++ (0,1) -| node[circle,draw,pos=0.25,fill=white]{A} (R);
draw (spring) -- ++ (-2.5,0) node[left](spring) {spring};
draw (coil) -- ++ (-2.5,0);
node[anchor=west,fill=white] at (spring.west |- coil) {coil};
draw (R) -- ++ (1.5,0) node[right] (terminal) {terminal};
begin{scope}
clip[rounded corners]
([xshift=-2.8cm]bottom -| left) -- ([xshift=2.8cm]bottom -| right)
|- ++ (-2,-2) -| cycle;
draw[fill=gray!30,decoration={random steps,segment length=2mm}]
([xshift=-3cm,yshift=-4mm]bottom -| left) [decorate]-- ([xshift=3cm,yshift=-4mm]bottom -|
right) |- ++ (-2,-2) -| cycle;
end{scope}
path (bottom -| left) -- (bottom -| right)
coordinate[midway,yshift=-1cm] (aux0)
coordinate[midway,yshift=-1.7cm] (aux1)
coordinate[pos=0.4,yshift=-2mm] (aux2)
coordinate[pos=0.6,yshift=-2mm] (aux3);
draw[fill=gray] (bottom -| left) |- (aux2)
-- (aux1) -- (aux3) -| (bottom -| right);
draw (aux0) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- aux0) {spike in\
ground};
draw (plane) -- ++ (3,0);
node[anchor=west,fill=white,align=left] at (terminal.west |- plane)
{oscillating\ magnet};
end{tikzpicture}
end{document}
This is just for fun. In principle you could employ pgfplots for that. I focus on the cube and the spiral.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16,width=8cm}
begin{document}
begin{tikzpicture}[declare function={spiralz(x,y)=x/360+y;}]
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{2}
begin{axis}[hide axis,view={40}{35},set layers,
cube/size x=cubex cm,cube/size y=cubey cm,cube/size z=cubez cm]
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain=pgfkeysvalueof{/pgfplots/view/az}:{pgfkeysvalueof{/pgfplots/view/az}+180},mesh,point meta=x,color=black,
on layer=axis background] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
addplot3 [only marks,mark=cube*,mark size=7,
on layer=pre main,color=yellow] coordinates {(0,0,10)};
pgfplotsinvokeforeach{1,...,10}{
addplot3[domain={pgfkeysvalueof{/pgfplots/view/az}+180}:{pgfkeysvalueof{/pgfplots/view/az}+360},mesh,point meta=x,color=black,
on layer=axis foreground] ({R*cos(x)},{R*sin(x)},{2*spiralz(x,#1)});
}
%typeout{pgfkeysvalueof{/pgfplots/view/az},pgfkeysvalueof{/pgfplots/view/el}}
end{axis}
end{tikzpicture}
end{document}
The advantage of this is that you have orthographic projections and can adjust the view. The disadvantage is the compilation time.
In order to speed up, one can use tikz-3dplot
, which requires to distinguish 4 cases (in this animation).
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{calc,3d}
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane
}
makeatother
pgfkeys{plane scale/.store in=PlaneScale,
plane scale=1}
newcommand{DrawPlane}[4]{
draw[canvas is #2,#1]
({-0.5*PlaneScale*#3},{-0.5*PlaneScale*#4}) rectangle
({0.5*PlaneScale*#3},{0.5*PlaneScale*#4});
}
newcommand{DrawSinglePlane}[2]{
ifcase#2
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=-cubez/2}{cubex}{cubey} % 1st xy plane
or
pgfmathtruncatemacro{myint}{60+40*cos(tdplotmaintheta)}
DrawPlane[fill=blue!myint,#1]{xy plane at z=cubez/2}{cubex}{cubey} % 2nd xy plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=-cubey/2}{cubex}{cubez} % 1st xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(cos(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{xz plane at y=cubey/2}{cubex}{cubez} % 2nd xz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=-cubex/2}{cubey}{cubez} % 1sy uz plane
or
pgfmathtruncatemacro{myint}{60+40*abs(sin(tdplotmainphi))}
DrawPlane[fill=blue!myint,#1]{yz plane at x=cubex/2}{cubey}{cubez} % 2nd uz plane
fi
}
begin{document}
foreach X in {0,5,...,355}
{tdplotsetmaincoords{90-40*sin(X)}{X} % the first argument cannot be larger than 90
begin{tikzpicture}
pgfmathsetmacro{cubex}{1}
pgfmathsetmacro{cubey}{.71}
pgfmathsetmacro{cubez}{3}
pgfmathsetmacro{R}{1.2}
path[use as bounding box] (-2*R,-2.4*R) rectangle (2*R,2.4*R);
begin{scope}[tdplot_main_coords]
% draw[thick,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
% draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
% draw[thick,->] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
path let p1=(1,0,0) in
pgfextra{pgfmathtruncatemacro{xproj}{sign(x1)}xdefxproj{xproj}};
pgfmathtruncatemacro{zproj}{sign(cos(tdplotmaintheta))}
%xdefzproj{zproj}
% node[anchor=north west] at (current bounding box.north west)
% {tdplotmaintheta,tdplotmainphi,zproj,xproj};
ifnumzproj=1
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
ifnumzproj=1
ifnumxproj=1
foreach XX in {2,3,6}
{DrawSinglePlane{XX}}
else
foreach XX in {4,6,2}
{DrawSinglePlane{XX}}
fi
else
ifnumxproj=1
foreach XX in {2,4,6}
{DrawSinglePlane{XX}}
else
foreach XX in {3,6,2}
{DrawSinglePlane{XX}}
fi
fi
ifnumzproj=1
foreach Y in {-5,...,5}
{foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi+180:tdplotmainphi+360]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
}
else
foreach Y in {-5,...,5}
{draw plot[variable=x,domain=tdplotmainphi:tdplotmainphi+180]
({R*cos(x)},{R*sin(x)},{0.1*(x/360+Y)});}
fi
end{scope}
end{tikzpicture}}
end{document}
edited Dec 16 '18 at 4:54
answered Dec 15 '18 at 23:58
marmot
88.3k4102190
88.3k4102190
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464864%2fdraw-a-technical-instrument-geophone%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You need to write why you want help. I am too lazy is not a valid reason - What is causing you problems? What have you tried?
– hpekristiansen
Dec 14 '18 at 17:39
Yes, exactly the coil, and the ground as well.
– Thumbolt
Dec 15 '18 at 1:57
For the ground, you could use some something like
draw[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]...
or see tex.stackexchange.com/questions/39296/… for ideas.– hpekristiansen
Dec 15 '18 at 2:05
Now I can draw the ground. How about the shading under the ground?
– Thumbolt
Dec 15 '18 at 3:52