我正在尝试绘制与该线程中的图像类似的图像:
如果你看一下杰克的回答,我想稍微修改一下......
\begin{tikzpicture}[]
\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]
\node [style={draw,outer sep=0pt,thick}] (M) [minimum width=1cm, minimum height=2.5cm] {$m$};
\node (ground) [ground,anchor=north,yshift=-0.25cm,minimum width=5.6cm,xshift=-0.03cm] at (M.south) {};
\draw (ground.north east) -- (ground.north west);
\draw (ground.south east) -- (ground.south west);
\draw (ground.north east) -- (ground.south east);
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {};
\draw (fill.north west) -- (fill.south west);
\draw (fill.south west) -- (fill.south east);
\draw [thick] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\draw [thick] (M.south west) ++ (2.5cm,-0.625cm) circle (0.25cm) (M.south east) ++ (-2.5cm,-0.625cm) circle (0.25cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
\draw (wall.north east) -- (wall.north west);
\draw (wall.north west) -- (wall.south west);
\draw (wall.south west) -- (wall.south east);
\node (y) at (M.east) [xshift = 1.2cm] {$y$};
\draw [spring] (wall.170) -- ($(M.north west)!(wall.170)!(M.south west)$);
\draw [damper] (wall.10) -- ($(M.north west)!(wall.10)!(M.south west)$);
\node (b) at (wall.10) [xshift = 1.2cm,yshift=0.55cm] {$b$};
\node (k) at (wall.170) [xshift = 1.2cm,yshift=0.35cm] {$k$};
\draw [-latex,ultra thick] (M.east) ++ (0cm,0cm) -- +(1cm,0cm);
\draw [-latex,ultra thick] (wall.north west) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\draw [dashed] (wall.north west) ++ (0cm, 0cm) -- +(0cm,0.8cm);
\end{tikzpicture}
注意称为的节点(fill)
,它们用于确保质量表面m
是一个连续的表面(手推车……)然而,放大后,我看到线条之间不连续。我该如何解决这个问题?
我是 Tikz 的新手,因此我希望找到一个不会让我完全失望的解决方案 - 简单的解决方案会更受赞赏。
因此,我现在正尝试绘制第二张图像,并且它几乎完成了,除了一些小故障......(我选择不创建新线程,因为它几乎是相同的代码......)
我怎样才能使地板的高度与墙的宽度相同?当我更改它时,它会画出一些奇怪的东西……
\begin{center}\hspace*{-4.5cm}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3},
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={minimum width=0.75cm,minimum height=0.3cm}
]
\node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1.5cm] {$m_1$};
\node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1.5cm, xshift = 4cm] {$m_2$};
\draw [thick, fill=white] (M2.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M2.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\node (ground) [anchor=north,minimum width=13cm] at (M.south) {};
\draw [spring] (M.east) -- (M2.west);
\draw [thick, fill=white] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\node (wall) [rotate=-90, minimum width=3cm,yshift=-3cm] {};
\draw[pattern=north east lines ] (wall.south west)|-(ground.south east)|-(wall.north east)|- cycle;
\draw [damper] (wall.75) -- ($(M.north west)!(wall.75)!(M.south west)$);
\node (b) at (wall.75) [xshift = 1cm,yshift=0.55cm] {$b$};
\node (k) at (wall.75) [xshift = 4.85cm,yshift=0.35cm] {$k$};
\draw [-latex,ultra thick] (M2.east) ++ (0cm,0cm) -- +(1cm,0cm);
\draw [-latex,ultra thick] (M.north east) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\draw [dashed] (M.north east) ++ (0cm, 0cm) -- +(0cm,0.8cm);
\node (y1) at (M.north east) [xshift = 1.2cm, yshift = 0.5cm] {$y_1$};
\draw [-latex,ultra thick] (M2.north east) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\draw [dashed] (M2.north east) ++ (0cm, 0cm) -- +(0cm,0.8cm);
\node (y1) at (M2.north east) [xshift = 1.2cm, yshift = 0.5cm] {$y_2$};
\end{tikzpicture}
\end{center}
我已经迁移到另一种解决方案:
\begin{center}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
\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,inner sep=0pt,outer sep=0pt]
\node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1.5cm] {$m_1$};
\node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1.5cm, xshift = 4cm] {$m_2$};
\draw [thick, fill=white] (M2.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M2.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
%\node (ground) [anchor=north,minimum width=13cm] at (M.south) {};
\node (ground) [ground,anchor=north,yshift=-0.2cm,minimum width=10cm,xshift=2.03cm] at (M.south) {};
\draw (ground.north east) -- (ground.north west);
\draw (ground.south east) -- (ground.south west);
\draw (ground.north east) -- (ground.south east);
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {};
\draw (fill.north west) -- (fill.south west);
\draw (fill.south west) -- (fill.south east);
\draw [spring] (M.east) -- (M2.west);
\draw [thick, fill=white] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,anchor=south east] at (fill.north west) {};
\draw (wall.north east) -- (wall.north west);
\draw (wall.north west) -- (wall.south west);
\draw (wall.south west) -- (wall.south east);
%\node (wall) [rotate=-90, minimum width=3cm,yshift=-3cm] {};
%\draw[pattern=north east lines ] (wall.south west)|-(ground.south east)|-(wall.north east)|- cycle;
\draw [damper] (wall.15) -- ($(M.north west)!(wall.15)!(M.south west)$);
\node (b) at (wall.15) [xshift = 1cm,yshift=0.55cm] {$b$};
\node (k) at (wall.15) [xshift = 4.85cm,yshift=0.35cm] {$k$};
\draw [-latex,ultra thick] (M2.east) ++ (0cm,0cm) -- +(1cm,0cm);
\draw [-latex,ultra thick] (M.north east) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\draw [dashed] (M.north east) ++ (0cm, 0cm) -- +(0cm,0.8cm);
\node (y1) at (M.north east) [xshift = 1.2cm, yshift = 0.5cm] {$y_1$};
\draw [-latex,ultra thick] (M2.north east) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\draw [dashed] (M2.north east) ++ (0cm, 0cm) -- +(0cm,0.8cm);
\node (y1) at (M2.north east) [xshift = 1.2cm, yshift = 0.5cm] {$y_2$};
\node (y1) at (M2.east) [xshift = 1.05cm] {$u$};
\end{tikzpicture}
\end{center}
答案1
角框北侧和东侧的白色空间是由于节点默认具有非零值inner sep
。outer sep
可以进行的其他更改是相对于其他节点定位节点以及使用节点锚点。
只需添加inner sep=0pt,outer sep=0pt
即可\tikzstyle{ground}{...}
解决角落方块的问题。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}
\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,inner sep=0pt,outer sep=0pt]
\node [style={draw,outer sep=0pt,thick}] (M) [minimum width=1cm, minimum height=2.5cm] {$m$};
\node (ground) [ground,anchor=north,yshift=-0.25cm,minimum width=5.6cm,xshift=-0.03cm] at (M.south) {};
\draw (ground.north east) -- (ground.north west);
\draw (ground.south east) -- (ground.south west);
\draw (ground.north east) -- (ground.south east);
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {};
\draw (fill.north west) -- (fill.south west);
\draw (fill.south west) -- (fill.south east);
\draw [thick] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\draw [thick] (M.south west) ++ (2.5cm,-0.625cm) circle (0.25cm) (M.south east) ++ (-2.5cm,-0.625cm) circle (0.25cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
\draw (wall.north east) -- (wall.north west);
\draw (wall.north west) -- (wall.south west);
\draw (wall.south west) -- (wall.south east);
\node (y) at (M.east) [xshift = 1.2cm] {$y$};
\draw [spring] (wall.170) -- ($(M.north west)!(wall.170)!(M.south west)$);
\draw [damper] (wall.10) -- ($(M.north west)!(wall.10)!(M.south west)$);
\draw [-latex,ultra thick] (M.east) ++ (0cm,0cm) -- +(1cm,0cm);
\end{tikzpicture}
\end{document}
然而,垂直的墙面位置仍然不太合适,我们可以替换\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
为\node (wall) [ground, rotate=-90, minimum width=3cm,anchor=south east] at (fill.north west) {};
指定south east
墙角后它已旋转了-90
度(因此在图像中角落south west
)应该位于north west
角块的角落处。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}
\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,inner sep=0pt,outer sep=0pt]
\node [style={draw,outer sep=0pt,thick}] (M) [minimum width=1cm, minimum height=2.5cm] {$m$};
\node (ground) [ground,anchor=north,yshift=-0.25cm,minimum width=5.6cm,xshift=-0.03cm] at (M.south) {};
\draw (ground.north east) -- (ground.north west);
\draw (ground.south east) -- (ground.south west);
\draw (ground.north east) -- (ground.south east);
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {};
\draw (fill.north west) -- (fill.south west);
\draw (fill.south west) -- (fill.south east);
\draw [thick] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\draw [thick] (M.south west) ++ (2.5cm,-0.625cm) circle (0.25cm) (M.south east) ++ (-2.5cm,-0.625cm) circle (0.25cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,anchor=south east] at (fill.north west) {};
\draw (wall.north east) -- (wall.north west);
\draw (wall.north west) -- (wall.south west);
\draw (wall.south west) -- (wall.south east);
\node (y) at (M.east) [xshift = 1.2cm] {$y$};
\draw [spring] (wall.170) -- ($(M.north west)!(wall.170)!(M.south west)$);
\draw [damper] (wall.10) -- ($(M.north west)!(wall.10)!(M.south west)$);
\draw [-latex,ultra thick] (M.east) ++ (0cm,0cm) -- +(1cm,0cm);
\end{tikzpicture}
\end{document}
为了响应 OP 更新的代码,我做了一些更改,主要是沿路径定义节点,以便更自动地放置它们。例如
\draw [-latex,ultra thick] (M.north east) ++ (0cm, 0.5cm) -- +(1cm,0cm);
\node (y1) at (M.north east) [xshift = 1.2cm, yshift = 0.5cm] {$y_1$};
可以替换为
\draw [-latex,ultra thick] (M.north east) ++(0cm, 0.5cm) -- +(1cm,0cm) node [right] (y1) {$y_1$};
它将y1
节点放置在刚刚绘制的箭头的末端,在我看来,这已经将标签$y_1$
置于自然位置,对我来说,这比定义节点相对于箭头起点的位置更有意义。当然,仍然可以使用xshift
和yshift
进行精细定位,但现在这些移位只需要进行小得多的调整(正如我下面所做的定位节点b
)。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
\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,inner sep=0pt,outer sep=0pt]
\node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1.5cm] {$m_1$};
\node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1.5cm, xshift = 4cm] {$m_2$};
\draw [thick, fill=white] (M2.south west) ++(0.2cm,-0.125cm) circle (0.125cm) (M2.south east) ++(-0.2cm,-0.125cm) circle (0.125cm);
\node (ground) [ground,anchor=north,yshift=-0.2cm,minimum width=10cm,xshift=2.03cm] at (M.south) {};
\draw (ground.north west) -- (ground.north east) -- (ground.south east) -- (ground.south west);
\node (fill) [ground,xshift=-0.15cm,minimum height = 0.3cm, minimum width = 0.3cm] at (ground.west) {};
\draw (fill.north west) -- (fill.south west) -- (fill.south east);
\draw [spring] (M.east) -- (M2.west) node (k) [midway,above] {$k$};
\draw [thick, fill=white] (M.south west) ++(0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++(-0.2cm,-0.125cm) circle (0.125cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,anchor=south east] at (fill.north west) {};
\draw (wall.north east) -- (wall.north west) -- (wall.south west) -- (wall.south east);
\draw [damper] (wall.15) -- ($(M.north west)!(wall.15)!(M.south west)$) node [midway,yshift=0.5cm] {$b$};
\draw [-latex,ultra thick] (M2.east) -- +(1cm,0cm) node [right] (u) {$u$};
\draw [-latex,ultra thick] (M.north east) ++(0cm, 0.5cm) -- +(1cm,0cm) node [right] (y1) {$y_1$};
\draw [dashed] (M.north east) -- +(0cm,0.8cm);
\draw [-latex,ultra thick] (M2.north east) ++(0cm, 0.5cm) -- +(1cm,0cm) node [right] (y2) {$y_2$};
\draw [dashed] (M2.north east) -- +(0cm,0.8cm);
\end{tikzpicture}
\end{document}
答案2
新答案
正如 Hans-Peter E. Kristiansen 指出的那样,我最初的假设(原始答案)patterns
是错误的,尽管它不会使解决方案无效。
无论如何,我一直在努力解决看似 OP 的问题:How to draw a filled wall+ground corner with a certain width
。
我之前的回答和戴博文的回答都是以未绘制的节点为基础的,后来这些节点被用作绘制图案角的参考。
在这种情况下,我展示了另一种方法。
首先,绘制带有(或不带有)所有所需标签的机械系统:
现在我们想绘制一个足够大的地面角来容纳系统。但可能我们不知道或不想计算系统尺寸。没问题,TikZ
可以帮助我们,因为在每个绘图命令之后,它都会计算一个current bounging box
足够大的节点来包含到目前为止所绘制的内容。这就是下图中虚线红色矩形所示的内容:
并且这个current bounding box
节点的角可以作为参考来绘制所需的墙面和地面。
作为示例,\drawwall
已定义命令来简化此任务。它使用三个参数,第一个是current bounding box.north
与墙最顶部线之间的垂直距离,第二个是current bounding box.east
与地面最右端之间的距离,第三个是墙/地面宽度。
%#1 - vertical oversize
%#2 - horizontal oversize
%#3 - wall width
\newcommand{\drawwall}[3]{%
\draw[ground]%
(current bounding box.south west)|-
([shift={(-#3,#1)}]current bounding box.north west)|-
([shift={(#2,-#3)}]current bounding box.south east)|-
cycle;
}
通过这个命令很容易获得:
或者
无需担心系统尺寸、规模……
前面示例的完整代码是:
\documentclass[border=3mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,
decorations.markings,
calc, patterns,
positioning}
%#1 - vertical oversize
%#2 - horizontal oversize
%#3 - wall width
\newcommand{\drawwall}[3]{%
\draw[ground]%
(current bounding box.south west)|-
([shift={(-#3,#1)}]current bounding box.north west)|-
([shift={(#2,-#3)}]current bounding box.south east)|-
cycle;
}
\tikzset{%
spring/.style={thick,
decorate,
decoration={zigzag,
pre length=0.3cm,
post length=0.3cm,
segment length=6}},
damper/.style={thick,
decorate,
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)$);
}}},
ground/.style={pattern = north east lines},
mass/.style={draw, thick, outer sep=0pt,
minimum width=2cm, minimum height=1.5cm},
wheel/.style={draw, thick, circle, outer sep=0pt,
inner sep=0pt, minimum size=.25cm, anchor=north},
force/.style={-latex, ultra thick},
}
\begin{document}
\begin{tikzpicture}[scale=1.1,
every node/.style={scale=1.3},
]
\node [mass] (M1) {$m_1$};
\node [wheel] at ([xshift=3mm]M1.south west) (W11) {};
\node [wheel] at ([xshift=-3mm]M1.south east) (W12) {};
\node [mass, right= 3cm of M1] (M2) {$m_2$};
\node [wheel] at ([xshift=3mm]M2.south west) (W21) {};
\node [wheel] at ([xshift=-3mm]M2.south east) (W22) {};
\draw [spring] (M1.east) -- node[above=3mm] {$k$} (M2.west);
\draw [damper] (M1.west) -- node[above=3mm] {$b$} ++(180:2cm);
\draw [dashed] (M1.north east)--++(90:8mm);
\draw [force] ([yshift=4mm]M1.north east)--++(0:1cm) node [right] {$y_1$};
\draw [dashed] (M2.north east)--++(90:8mm);
\draw [force] (M2.east)--++(0:1cm) node[right] {$u$};
\draw [force] ([yshift=4mm]M2.north east)--++(0:1cm) node[right] {$y_2$};
\draw[dashed, red!30, thin] (current bounding box.north west) rectangle (current bounding box.south east);
\drawwall{5mm}{5mm}{5mm}
\end{tikzpicture}
\begin{tikzpicture}
\node [mass, minimum height=4cm] (M1) {$m_1$};
\node [wheel] at ([xshift=3mm]M1.south west) (W11) {};
\node [wheel] at ([xshift=-3mm]M1.south east) (W12) {};
\draw [spring] ([yshift=1cm]M1.west) -- node[above=3mm] {$k$} ++(180:2cm);
\draw [damper] ([yshift=-1cm]M1.west) -- node[above=3mm] {$b$} ++(180:2cm);
\draw[dashed, red!30, thin] (current bounding box.north west) rectangle (current bounding box.south east);
\drawwall{5mm}{5mm}{5mm}
\end{tikzpicture}
\end{document}
原始答案
我认为每个patterns
都有自己的起源,因此它们在每个节点内都是独立绘制的。
因此,如果您想获得连续的图案,您应该将填充区域声明为一个整体。
我在下面的代码中所做的就是保留你的ground
和wall
节点作为参考,但不绘制或填充任何图案。一旦它们存在,它们就可以用来声明整个区域:
\draw[pattern=north east lines ] (wall.south west)|-(ground.south east)|-(wall.north east)|- cycle;
为了理解上一行,您应该记住wall
节点已旋转(rotate=-90
),因此其左上角是south west
而不是north west
,而右下角是north east
。
有了先前的声明,fill
节点就不再需要了。
我还将tikzstyle
弃用的声明更改为tikzstyle
。
\documentclass[border=2mm, tikz]{standalone}
\usetikzlibrary{patterns, calc, decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[
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={minimum width=0.75cm,minimum height=0.3cm}
]
\node [draw, outer sep=0pt, thick] (M) [minimum width=1cm, minimum height=2.5cm] {$m$};
\node (ground) [anchor=north,yshift=-0.25cm,minimum width=5.6cm,xshift=-0.03cm] at (M.south) {};
\draw [thick] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\draw [thick] (M.south west) ++ (2.5cm,-0.625cm) circle (0.25cm) (M.south east) ++ (-2.5cm,-0.625cm) circle (0.25cm);
\node (wall) [rotate=-90, minimum width=3cm,yshift=-3cm] {};
\draw[pattern=north east lines ] (wall.south west)|-(ground.south east)|-(wall.north east)|- cycle;
\node (y) at (M.east) [xshift = 1.2cm] {$y$};
\draw [spring] (wall.170) -- ($(M.north west)!(wall.170)!(M.south west)$);
\draw [damper] (wall.10) -- ($(M.north west)!(wall.10)!(M.south west)$);
\draw [-latex,ultra thick] (M.east) ++ (0cm,0cm) -- +(1cm,0cm);
\end{tikzpicture}
\end{document}