将一条线(固定长度)附加到用 tikz 线圈绘制的弹簧上

将一条线(固定长度)附加到用 tikz 线圈绘制的弹簧上

看看这里的好答案:在 TikZ 中绘制机械弹簧,我想将一条固定长度(比如说 5 毫米)的线连接到弹簧的顶部(到平台)和弹簧的底部(到质量)。

这里的关键是我希望这些段保持(长度为 5 毫米),无论上述帖子答案中的弹簧是未压缩的还是压缩的。

编辑:这是我目前所得到的,但是从线圈底部到质量顶部的线性段给我带来了麻烦。

\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]

\node (g) [platform,anchor=north] {};

\node[draw=none,below=1.25cm of g,inner sep=-2,minimum size=0mm] (topspring){};

\node[draw=none,below=1.25cm of topspring] (bottomspring){};
\node[draw=none,below=.5cm of bottomspring] (attachment){};

\node[circle,below=.5cm of attachment] (pt2){$m$};

\draw [dampener](topspring.north)--(g.south) node[draw=none,pos=.52,right=.4cm] {$b$};
\draw [spring] (topspring.south) -- (bottomspring.north) node[draw=none,pos=.5,right=.25cm] {$k$};
\draw [thick] (bottomspring) -- (attachment);

\end{tikzpicture}

在此处输入图片描述

编辑#2:对 Harish 的答案进行一点修改使我得到了我想要的外观,线圈的紧密度随着质量的位移而变化。

在此处输入图片描述

编辑#3:Harish 的答案为调整多个参数提供了一个非常有效的解决方案。

答案1

我觉得我没有理解清楚。但是,是这样的吗?

\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}

在此处输入图片描述

编辑:回答评论中的问题:

我们可以用\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}

在此处输入图片描述

编辑:进行一些进一步的美化以融入当前案例的物理意义:

\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}

在此处输入图片描述

这里\myfig需要四个参数。第一个是segment length,第二个是弹簧的拉伸位置(坐标bottomspring),第三个是包围的圆的半径m,最后一个是的字体大小m。因此,必须\myfig{3mm}{-10cm}{-0.4cm}{1.4}根据需要使用适当的值。

相关内容