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
This is a work around using
\clip
.Note that a line width of
2pt
will give a resultant line width of1pt
as the other part is clipped off. So you have to adjust properly.If this forms a part of bigger diagram, the
\clip
ping part may be enclosed in ascope
so as to limit the clipping: