我尝试移除或隐藏连接左侧wall
和第一个块的线$m_1$
,但没有成功。我该怎么做?我认为这很容易,但我不知道具体怎么做。
代码如下:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{
decorations.markings,
decorations.pathmorphing,
calc,
patterns,
positioning
}
\tikzset{
spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}},
blank/.style={draw=none,fill=none,pos=0.5},
ground/.style={fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm},
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=10pt,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,-3pt)$) -- ($(dmp.north)+(0,3pt)$);
}
}, decorate
},
box/.style={draw,thick,minimum width=1cm, minimum height=1cm}
}
\begin{document}
\begin{figure}[tbp]
\centering
\begin{tikzpicture}[node distance=3cm]
\node (wall) [ground, rotate=-90, minimum width=2cm] {};
\node (M1) [box, right=of wall.north] {$m_1$};
\node (M2) [box,right=of M1,label=below:$f$] {$m_2$};
\draw (wall.north east) -- (wall.north west);
\draw [spring] (wall.north) -- (M1) node[blank,above,yshift=1mm] {};
\draw (wall.20) -- (wall.20 -| M1.west) coordinate (d1);
\draw [spring] (M1) -- (M2) node[blank,above,yshift=1mm] {} ;
\draw [damper] (d1-|M1.east) -- (d1 -| M2.west);
\node (wall2) [ground, right=of M2, anchor=north,rotate=90,minimum width=2cm] {};
\draw [spring] (M2) -- (wall2) node[blank,above,yshift=1mm] {};
\draw [damper] (d1-|M2.east) -- (d1 -| wall2.north);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
替换\draw
为\path
:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{
decorations.markings,
decorations.pathmorphing,
calc,
patterns,
positioning
}
\tikzset{
spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}},
blank/.style={draw=none,fill=none,pos=0.5},
ground/.style={fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm},
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=10pt,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,-3pt)$) -- ($(dmp.north)+(0,3pt)$);
}
}, decorate
},
box/.style={draw,thick,minimum width=1cm, minimum height=1cm}
}
\begin{document}
\begin{figure}[tbp]
\centering
\begin{tikzpicture}[node distance=3cm]
\node (wall) [ground, rotate=-90, minimum width=2cm] {};
\node (M1) [box, right=of wall.north] {$m_1$};
\node (M2) [box,right=of M1,label=below:$f$] {$m_2$};
\draw (wall.north east) -- (wall.north west);
\draw [spring] (wall.north) -- (M1) node[blank,above,yshift=1mm] {};
\path (wall.20) -- (wall.20 -| M1.west) coordinate (d1);
\draw [spring] (M1) -- (M2) node[blank,above,yshift=1mm] {} ;
\draw [damper] (d1-|M1.east) -- (d1 -| M2.west);
\node (wall2) [ground, right=of M2, anchor=north,rotate=90,minimum width=2cm] {};
\draw [spring] (M2) -- (wall2) node[blank,above,yshift=1mm] {};
\draw [damper] (d1-|M2.east) -- (d1 -| wall2.north);
\end{tikzpicture}
\end{figure}
\end{document}
答案2
我想扩展一下伊格纳西。
您还可以通过添加选项使任何线条不可见
draw=none
到正在绘制的 tikz 命令。此选项有一些优点我在下面评论。
在你的情况下,你必须改变路线
\draw (wall.20) -- (wall.20 -| M1.west) coordinate (d1);
经过
\draw[draw=none] (wall.20) -- (wall.20 -| M1.west) coordinate (d1);
优点
参见 TikZ 手册 3.1.5b 第 15.3 节绘制路径:“如果没有指定特殊颜色名称,则此选项会导致绘图“关闭”。如果样式先前已打开绘图并且您希望在本地撤消此效果,则此功能很有用。”
举一个实用性的例子,假设你有一个范围,其中所有节点框架都设置为绘制(every node/.style=draw
),但你想做一个例外(参见节点 C)
\begin{tikzpicture}
\begin{scope}[every node/.style=draw]
\path (0,0) node{A};
\path (0,1) node{B};
\path (1,0) node[draw=none]{C};
\path (1,1) node{D};
\end{scope}
\end{tikzpicture}
请注意,在这个特殊情况下,解决方案samcarter_is_at_topanswers.xyz不能使用。 ;)