我没有深入研究绘制一行阻尼器和弹簧的语法(它们之间没有质量或其他任何东西):我所能做的就是将它们平行绘制:另一件事:我如何控制弹簧的长度?
非常感谢您的帮助!
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\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)+(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{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm]
\begin{scope}[xshift=7cm]
\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
\node (walle) [ground, rotate=-90, minimum width=3cm,yshift=3cm] {};
\draw (wall.north east) -- (wall.north west);
\draw (walle.south west) -- (walle.south east);
\draw [spring, width=15pt] (wall.170) -- ($(walle.south west)!(walle.170)!(walle.south east)$);
\draw [damper] (wall.10) -- ($(walle.south west)!(walle.10)!(walle.south east)$);
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\end{scope}
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\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)+(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{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm]
\begin{scope}[xshift=7cm]
\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
\node (walle) [ground, rotate=-90, minimum width=3cm,yshift=3cm] {};
\draw (wall.north east) -- (wall.north west);
\draw (walle.south west) -- (walle.south east);
\draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(3.5cm,0)coordinate (m);
\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\end{scope}
\end{tikzpicture}
\end{document}
如何改进代码?
首先不要使用\tikzstyle
但是tikzset
。不要旋转单个节点,而是先绘制它们并旋转整个部分。这使您(wall.north east)
更容易可视化方向和锚点(例如等)。
此外,您可以使用相对坐标设置弹簧的长度,例如:
\draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,3.5cm);
这意味着 - “从距离总长度 0.2 的点向西北和东北方向(从西北测量)”。-- ++(0,3.5cm)
意味着 - 到 x 方向 0 厘米和 y 方向 3.5 厘米的距离”。
绘制弹簧后,我们在弹簧末端放置一个坐标
............++(0,3.5cm)coordinate (m);
从(m)
我们绘制damper
到walle
:
\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);
第二部分如前所述。
完整代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\tikzset{
spring/.style = {thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment
length=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)+(2pt,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.75cm,minimum height=0.3cm}
}
\begin{scope}[rotate=-90,transform shape] %%% rotate here, both options needed.
\node (wall) [ground, minimum width=3cm,anchor=center] at (0,0) {};
\node (walle) [ground, minimum width=3cm,anchor=center] at (0,6) {};
\draw (wall.north east) -- (wall.north west);
\draw (walle.south west) -- (walle.south east);
\draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,3.5cm)coordinate (m);
\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);
%
%% now a parallel spring
\draw [spring, line width=15pt] ($(wall.north west)!0.8!(wall.north east)$) -- ($(walle.south west)!0.8!(walle.south east)$);
%\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\end{scope}
\end{tikzpicture}
\end{document}
结果是:
答案2
非常感谢! 以下是我的最终代码,供大家参考:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\tikzset{
spring/.style = {thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment
length=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)+(1pt,0)$) -- (dmp.south east) -- (dmp.south
west) -- ($(dmp.north west)+(1pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate},
ground/.style ={fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm}
}
\begin{scope}[rotate=-90,transform shape] %%% rotate here, both options needed.
\node (wall) [ground, minimum width=3cm,anchor=center] at (0,0) {};
\node (walle) [ground, minimum width=3cm,anchor=center] at (0,6) {};
\draw (wall.north east) -- (wall.north west);
\draw (walle.south west) -- (walle.south east);
%% now a parallel spring
\draw [line width=0.8pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,2cm)coordinate (z);
\draw [spring] (z) -- ++(0,2cm)coordinate (t);
\draw [line width=0.8pt] (t) -- ($(walle.south west)!0.2!(walle.south east)$);
\end{scope}
\begin{scope}[rotate=-90,transform shape] %%% rotate here, both options needed.
\draw [line width=0.8pt] ($(wall.north west)!0.8!(wall.north east)$) -- ++(0,1cm)coordinate (z);
\draw [spring] (z) -- ++(0,2cm)coordinate (t);
\draw [damper] (t) -- ++(0,2cm)coordinate (u);
\draw [line width=0.8pt] (u) -- ($(walle.south west)!0.8!(walle.south east)$);
\end{scope}
\end{tikzpicture}
\end{document}