# Mechanical vibration diagrams using Tikz

I want to draw this: I managed to draw something like that:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{scope} [every node/.style={draw,outer sep=0pt,thick},place/.style={circle,fill=gray!20,thick,
inner sep=0pt,minimum size=6mm}]
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
\tikzstyle{damper}=[thick,decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with
{
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\draw [thick] ($(dmp.north east)+(2.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.3cm,minimum height=0.3cm]
\draw[domain=0:11.5,variable=\t,samples=440,smooth]
plot({(-\t+.1) r}:{\t/40+\t/10/(0.1+\t)});
\node (ground) [ground,anchor=north,minimum height=0.5cm] at ( 0.3,0.75) {};
\draw (ground.north east) -- (ground.south east);
\draw[ultra thick] (0,0)--(6,0);
\draw [spring] (6,0)--+(0,-2);
\node (gh) [ground,anchor=north,minimum width=1cm] at ( 6,-2) {};
\draw (gh.south east) -- (gh.south west);
\end{scope}

\end{tikzpicture}
\end{subfigure}

But it's not that good!

Could you help me?!

• why it's not goog – rpapa Oct 7 '16 at 14:01
• I want to add more details to it! – H.H Oct 7 '16 at 14:04
• What sort of details?? Specificity leads to good answers. – Guilherme Zanotelli Oct 7 '16 at 14:14
• Deatails of first picture – H.H Oct 7 '16 at 14:20
• @GuilhermeZ.Santos I guess OP wants to reproduce the diagram as close to the original as possible, but what OP has does not look so close. :-) – awllower Oct 7 '16 at 14:33

First tip should be: LaTeX does not care about spaces and enters! Organize your drawing, it's better to understand afterwards. Although I don't like the yellow bar:

### EDIT

As percusse comment below, the use of \tikzstyle is deprecated, use instead \tikzset to make the styles beforehand.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\tikzset{place/.style={  circle,
fill=gray!20,
thick,
inner sep=0pt,
minimum size=6mm},
spring/.style={ decorate,
decoration={zigzag,
pre length=0.3cm,
post length=0.3cm,
segment length=6,
amplitude=6
}
},
damper/.style={ thick,
decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with {\node (dmp) [thick,
inner sep=0pt,
transform shape,
rotate=-90,
minimum width=15pt,
minimum height=3pt,
draw=none] {};
\draw [thick] ($(dmp.north east)+(2.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
},
decorate
},
ground/.style={ fill,
pattern=north east lines,
draw=none,
minimum width=0.3cm,
minimum height=0.3cm
},
bar/.style={fill=yellow,
draw=black,
minimum width=6cm,
minimum height=0.2cm,
anchor=west
}
}

\begin{document}

\begin{tikzpicture}[>=latex,
every node/.style={outer sep = 0pt,
thick
}
]
% Bar drawing with its labels
\node[bar] (Bar) at (0,0) {};
\node[anchor=south east] at (Bar.north east) {$m$};
\node[anchor=south] at (Bar.north) {$\ell$};
% Theta angle in the middle
\draw[->] (10:2.5) arc[start angle=10, delta angle=-20, radius=2.5] node[anchor=west]{$\theta$};
% Neutral line and x axis
\draw[dash dot] (Bar.west) -- ($(Bar.east)+(0.75cm,0)$) node(Xaxis){};
\draw[thick,->] (Xaxis.center) -- +(0,-0.5cm)node[near end,anchor=west]{$x$};
% Spiral spring (damper) and its label
\draw[domain=0:11.5,variable=\t,samples=440,smooth] plot ({(-\t+.1) r}:{\t/40+\t/10/(0.1+\t)});
\node [anchor=south east, shift={(120:0.2)}] {$k_t$};
% Ground and its label
\node (Ground) [ground,anchor=north,minimum height=0.5cm] at ( 0.3,0.75) {};
\node[anchor=west] at (Ground.east) {$O$};
\draw (Ground.north east) -- (Ground.south east);
% Spring and its label
\draw [spring] (Bar.east) -- node[anchor=east,xshift=-0.5cm]{$k$} +(0,-2) node(EndSpring){};
% Spring base (other ground)
\node (SpringBase) [ground,anchor=north,minimum width=1cm] at (EndSpring) {};
\draw (SpringBase.south east) -- (SpringBase.south west);

\end{tikzpicture}

\end{document}

• It does care a lot!! TikZ doesn't care inside the environment and in /.style handler. And please use \tikzset instead. \tikzstyle is deprecated – percusse Oct 7 '16 at 14:48
• I normally used \tikzset already, I was focused on the OP's request and didn't know \tikzstyle was deprecated! Thanks (I'll edit when I get home). Still, how come LaTeX cares about spaces and enters? If you write Word (several spaces) word you'd still get `Word word'. Please englighten me (I mean that in the good way, I consider myself far from knowing anything about TeX). – Guilherme Zanotelli Oct 7 '16 at 14:56
• I think the input processor of TeX just enters the space skipping mode when encountering a character of category code 10 while in middle of line mode; after a control sequence or a control space (not including control symbols), it enters the space skipping mode as well. So yes, it is fair to say, in most circumstances, TeX does not care about spaces. – awllower Oct 7 '16 at 16:32
• TikZ uses \nullfont in its body to skip everything text. Hence effectively eats up spaces and other text though it still parses them. In the keys it strips off the pre and post white spaces. But TeX cares everything about spaces. You can read more about it tex.stackexchange.com/questions/7453/… Whitespace is a very important argument and cs delimiter too. There are other peculiarities – percusse Oct 7 '16 at 17:22
• @percusse, understood! I see that sometimes it can make a big difference... The most proper way to state what I've said is "In this case scenario, spaces and enters are ignored" or should I always use % at line ends instead? Because that sounds a little boring. :P – Guilherme Zanotelli Oct 7 '16 at 17:31

Here is an example:

\documentclass{standalone}
\usepackage{lmodern}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[very thick,fill=yellow](0.719,3.92) -- (5.92,3.92) -- (5.92,3.49) -- (0.719,3.49) -- cycle;
\draw (5.5,4.2) node{$m$};
\draw ((5.92/2+0.719/2,4.2) node {$\ell$};
\draw[dashdotted,thick](0.694,3.7) -- (6.56,3.7);
\draw[](0.741,3.7) .. controls (0.739,3.74) and (0.794,3.72) .. (0.808,3.71) .. controls (0.845,3.65) and (0.799,3.59) .. (0.749,3.57) .. controls (0.658,3.53) and (0.565,3.6) .. (0.542,3.69) .. controls (0.507,3.82) and (0.603,3.94) .. (0.726,3.97) .. controls (0.89,4) and (1.04,3.88) .. (1.07,3.72) .. controls (1.11,3.52) and (0.959,3.33) .. (0.764,3.3) .. controls (0.527,3.26) and (0.31,3.44) .. (0.276,3.68) .. controls (0.235,3.95) and (0.443,4.2) .. (0.711,4.23) .. controls (1.02,4.28) and (1.3,4.04) .. (1.34,3.74) .. controls (1.38,3.39) and (1.12,3.08) .. (0.779,3.04) .. controls (0.398,2.99) and (0.0532,3.28) .. (0.00979,3.66) .. controls (-0.0384,4.08) and (0.283,4.45) .. (0.696,4.5) .. controls (0.781,4.51) and (0.868,4.5) .. (0.952,4.49);
\draw (0,4.5) node{$k_t$};
\draw[thick,fill=blue](0.861,4.73) -- (1.03,4.73) -- (1.03,4.31) -- (0.861,4.31) -- cycle;
\draw (1.03,4.6) node[right] {$O$};
\draw[>=stealth,->](4.26,4.28) .. controls (4.85,4.28) and (4.86,3.12) .. (4.26,3.12)node [near end,right]{$\theta$};
\draw[very thick,>=stealth,->](6.56,3.7) -- (6.56,3.16) node[right]{$x$};
\draw[](5.92,3.49) -- (5.92,3.18) -- (6.22,3.1) -- (5.61,2.94) -- (6.21,2.79) -- (5.61,2.64) -- (6.21,2.48) -- (5.61,2.33) -- (6.21,2.18) -- (5.61,2.02) -- (6.21,1.87) -- (5.61,1.71) -- (6.21,1.56) -- (5.61,1.41) -- (6.21,1.25) -- (5.61,1.1) -- (6.21,0.944) -- (5.61,0.79) -- (6.21,0.636) -- (5.91,0.559) -- (5.91,0.251);
\draw[] (5.3,2) node[] {$k$};
\draw[thick](5.6,0.249) -- (6.23,0.249);
\draw[thin](5.59,0.173) -- (5.67,0.251);
\draw[thin](5.59,0.0535) -- (5.79,0.251);
\draw[thin](5.66,0.00368) -- (5.91,0.251);
\draw[thin](5.78,0.00368) -- (6.03,0.251);
\draw[thin](5.9,0.00368) -- (6.15,0.251);
\draw[thin](6.02,0.00368) -- (6.22,0.2);
\draw[thin](6.14,0.00368) -- (6.22,0.0805);
\end{tikzpicture}
\end{document}

• This is a very fixed way of drawing. If one wants to change the bar width for instance, would be in serious trouble! Consider the use of coordinates, positioning library or even nodes to turn fixed positions into relative positions in your future drawings. :D – Guilherme Zanotelli Oct 7 '16 at 15:00
• @GuilhermeZ.Santos your remark is true, it is a pretty fixed way of drawing, but still by analysing the code a few changes could be done. – ThomasGuenet Oct 7 '16 at 15:18