我拥有的:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, patterns, decorations.pathmorphing, decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzstyle{wheel} = [draw, circle]
\tikzstyle{mass} = [draw, rectangle, minimum height = 1cm, minimum width = 2cm]
\tikzstyle{spring} = [decorate, decoration = {zigzag, pre length = 0.3cm, post length = 0.3cm, segment length = 6}]
\tikzstyle{damper} = [decoration = {markings, mark connection node = dmp, mark = at position 0.5 with
{
\node (dmp) [inner sep = 0pt, transform shape, rotate = -90, minimum width = 5pt, minimum height = 5pt, draw=none] {};
\draw ($(dmp.north east)+(1.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(1.5pt,0)$);
\draw ($(dmp.north)+(0,-1.5pt)$) -- ($(dmp.north)+(0,1.5pt)$);
}
}, decorate]
\tikzstyle{groundflat} = [fill, pattern = north east lines, draw = none, minimum width = 0.75cm, minimum height = 0.3cm]
% \tikzstyle{groundsine1} = [fill, pattern = north east lines, draw = none, minimum width = 0.75cm, minimum height = 0.3cm]
\node[wheel] (u) {$u$};
\node[mass, above of = u, node distance = 3cm] (m) {$y$};
\node (gf) [groundflat, anchor = north, minimum width = 5cm] at (u.south) {};
\draw (gf.north east) -- (gf.north west);
\draw [-] (u.north) |- ++(0.5,0.25cm)coordinate (uright);
\draw [-] (u.north) |- ++(-0.5,0.25cm)coordinate (uleft);
\draw [spring] (uleft) -- ($(m.south) +(-0.5,0)$);
\draw [damper] (uright) -- ($(m.south) +(0.5,0)$);
\end{tikzpicture}
\end{document}
我现在希望地面呈正弦波并且车轮位于第一个峰上。
任何帮助,将不胜感激。
编辑:刚刚发现这个:Tikz 坐标定位
但我真的无法将它们组合在一起...
答案1
与先画机械方案再画地相比,画正弦波地线并将机器放置在其上更加容易。
在第 128 页pgfmanual
你可以看到如何绘制正弦线:
\draw (0,0) sin (1,.5) coordinate (top) cos (2,0) sin (3,-.5) cos (4,0) sin (5,.5) cos (6,0);
第一个峰位于坐标 (1,.5) 处(名为top
),我们可以将 放置wheel
在其顶部
\node[wheel, above=0pt of top] (u) {$u$};
由于方案的其余部分已基于绘制u
,因此您不需要进行太多更改。我已将旧语法更改above of=
为新语法above= of
(需要positioning
库,第 229 页)。
顺便说一句,请考虑将从 更改\tikzstyle
为\tikzset
语法:应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, patterns, decorations.pathmorphing, decorations.markings, positioning}
\begin{document}
\begin{tikzpicture}
\tikzstyle{wheel} = [draw, circle]
\tikzstyle{mass} = [draw, rectangle, minimum height = 1cm, minimum width = 2cm]
\tikzstyle{spring} = [decorate, decoration = {zigzag, pre length = 0.3cm, post length = 0.3cm, segment length = 6}]
\tikzstyle{damper} = [decoration = {markings, mark connection node = dmp, mark = at position 0.5 with
{
\node (dmp) [inner sep = 0pt, transform shape, rotate = -90, minimum width = 5pt, minimum height = 5pt, draw=none] {};
\draw ($(dmp.north east)+(1.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(1.5pt,0)$);
\draw ($(dmp.north)+(0,-1.5pt)$) -- ($(dmp.north)+(0,1.5pt)$);
}
}, decorate]
\tikzstyle{groundflat} = [fill, pattern = north east lines, draw = none, minimum width = 0.75cm, minimum height = 0.3cm]
\draw[fill, pattern=north east lines] (0,0) sin (1,.5) coordinate (top) cos (2,0) sin (3,-.5) cos (4,0) sin (5,.5) cos (6,0) |- (0,-1)--cycle;
\node[wheel, above=0pt of top] (u) {$u$};
\node[mass, above =2cm of u] (m) {$y$};
\draw [-] (u.north) |- ++(0.5,0.25cm)coordinate (uright);
\draw [-] (u.north) |- ++(-0.5,0.25cm)coordinate (uleft);
\draw [spring] (uleft) -- ($(m.south) +(-0.5,0)$);
\draw [damper] (uright) -- ($(m.south) +(0.5,0)$);
\end{tikzpicture}
\end{document}