This is a slightly adapted version of my answer to Nicer wavy line with TikZ. This version doesn't insist on drawing a full sine wave, but will be happy with half periods as well (i.e. it can start and end with an upward arch, while the previous version would always start with an upward and end with a downward arch):
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
\pgfdeclaredecoration{complete sines}{initial}
{
\state{initial}[
width=+0pt,
next state=upsine,
persistent precomputation={\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{upsine}[width=\pgfdecorationsegmentlength,next state=downsine]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
}
\state{downsine}[width=\pgfdecorationsegmentlength,next state=upsine]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}{}
}
\begin{tikzpicture}[
every path/.style={
decoration={
complete sines,
segment length=1cm,
amplitude=1cm
},
decorate,
thick
}]
\draw (0,0) -- (2,0);
\draw [yshift=-1.2cm] (0,0) -- (2.5,0);
\draw [yshift=-2.4cm] (0,0) -- (3,0);
\draw [yshift=-3.6cm] (0,0) -- (3.5,0);
\end{tikzpicture}
\end{document}
I do not think I understood you clearly. But, is it like this?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usetikzlibrary{calc,patterns,decorations.markings}
\usetikzlibrary{positioning,snakes}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\tikzstyle{spring}=[thick,decorate,decoration={aspect=0.5, segment length=1mm, amplitude=2mm,coil}]
\tikzstyle{dampener}=[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)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{platform}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\coordinate (g) at (0,0);
\coordinate (topspring) at (0,-1.25cm);
\coordinate (bottomspring) at (0,-4cm); %%changing the values (5cm) here will compress or expand the spring
\coordinate (pt2) at ($(bottomspring) + (0,-.5cm)$); %% this is relative.
\node [platform,anchor=south] at (g) {};
\draw[very thick] (-1,0) -- (1,0);
\draw [dampener](topspring)--(g) node[draw=none,pos=.52,right=0.25cm] {$b$};
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,right=.25cm] (spring){$k$};
\draw [thick] (bottomspring) -- (pt2.north);
\draw ($(pt2) + (0,-.2)$) circle (.2cm) node[draw=none,inner sep = 0]{$m$};
\end{tikzpicture}
\end{document}
Edit: To answer the query in the comment:
We can use \scope
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usetikzlibrary{calc,patterns,decorations.markings}
\usetikzlibrary{positioning,snakes}
\newcommand{\myfig}[1]{%
\coordinate (g) at (0,0);
\coordinate (topspring) at (0,-1.25cm);
\coordinate (bottomspring) at (0,{#1}); %%changing the values (5cm) here will compress or expand the spring
\coordinate (pt2) at ($(bottomspring) + (0,-.5cm)$); %% this is relative.
\node [platform,anchor=south] at (g) {};
\draw[very thick] (-1,0) -- (1,0);
\draw [dampener](topspring)--(g) node[draw=none,pos=.52,right=0.25cm] {$b$};
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,right=.25cm] (spring){$k$};
\draw [thick] (bottomspring) -- (pt2.north);
\draw ($(pt2) + (0,-.2)$) circle (.2cm) node[draw=none,inner sep = 0]{$m$};
}
\begin{document}
\begin{tikzpicture}[yshift=2cm,every node/.style={draw,outer sep=0pt,thick}]
\tikzstyle{spring}=[thick,decorate,decoration={aspect=0.5, segment length=1mm, amplitude=2mm,coil}]
\tikzstyle{dampener}=[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)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{platform}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\begin{scope}[xshift=-2.5cm]
\myfig{-2cm}
\end{scope}
\myfig{-4cm}
\begin{scope}[xshift=2.5cm]
\myfig{-6cm}
\end{scope}
\begin{scope}[xshift=5cm]
\myfig{-8cm}
\end{scope}
\begin{scope}[xshift=7.5cm]
\myfig{-10cm}
\end{scope}
\begin{scope}[xshift=10cm]
\myfig{-12cm}
\end{scope}
\end{tikzpicture}
\end{document}
Edit: Some more beautification to incorporate the physical meaning of the present case:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usetikzlibrary{calc,patterns,decorations.markings}
\usetikzlibrary{positioning}
\newcommand{\myfig}[4]{%
\tikzstyle{spring}=[thick,decorate,decoration={aspect=0.5, segment length=#1, amplitude=2mm,coil}]
\tikzstyle{dampener}=[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)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{platform}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\coordinate (g) at (0,0);
\coordinate (topspring) at (0,-1.25cm);
\coordinate (bottomspring) at (0,{#2}); %%changing the values (5cm) here will compress or expand the spring
\coordinate (pt2) at ($(bottomspring) + (0,-.5cm)$); %% this is relative.
\node [platform,anchor=south] at (g) {};
\draw[very thick] (-1,0) -- (1,0);
\draw [dampener](topspring)--(g) node[draw=none,pos=.52,right=0.25cm] {$b$};
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,right=.25cm] (spring){$k$};
\draw [thick] (bottomspring) -- (pt2.north);
\draw ($(pt2) + (0,#3)$) circle (#3) node[draw=none,inner sep = 0,scale=#4]{$m$};
}
\begin{document}
\begin{tikzpicture}[yshift=0cm,every node/.style={draw,outer sep=0pt,thick}]
\begin{scope}[xshift=-2.5cm]
\myfig{1mm}{-3cm}{-0.2cm}{1}
\end{scope}
\myfig{1.5mm}{-4.5cm}{-0.25cm}{1.1}
\begin{scope}[xshift=2.5cm]
\myfig{2mm}{-6cm}{-0.3cm}{1.2}
\end{scope}
\begin{scope}[xshift=5cm]
\myfig{2.5mm}{-8cm}{-0.35cm}{1.3}
\end{scope}
\begin{scope}[xshift=7.5cm]
\myfig{3mm}{-10cm}{-0.4cm}{1.4}
\end{scope}
\begin{scope}[xshift=10cm]
\myfig{3.5mm}{-12cm}{-0.45cm}{1.5}
\end{scope}
\end{tikzpicture}
\end{document}
Here \myfig
takes four arguments. First one is segment length
, second the stretching position of the spring (the coordinate bottomspring
), third is radius of the circle enclosing m
and the last is the font size for m
. Hence one has to use \myfig{3mm}{-10cm}{-0.4cm}{1.4}
with appropriate values as per the need.
Best Answer
You can use the
coil
decoration for the effect. Withsegment length
you can mimic the compression amount.