0

What I have:

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

I now want the ground to be a sine wave and the wheel sitting on the first peak.

Any help would be appreciated.

Edit: Just found this one: Tikz Cordinate Positioning

But I'm not really able to put it together...

Pascal
  • 307

1 Answers1

1

Instead of drawing the mechanical scheme before the ground, it's easier to draw the sinusoidal ground and place the machine on top of it.

On page 128 in pgfmanual you can see how to draw a sinusoidal line:

  \draw (0,0) sin (1,.5) coordinate (top) cos (2,0) sin (3,-.5) cos (4,0) sin (5,.5) cos (6,0);

The first peak is at coordinate (1,.5) (named top) and we can place the wheel on top of it with

  \node[wheel, above=0pt of top] (u) {$u$};

And as the rest of scheme is already drawn based on u, you won't need to many changes. I've changed old syntax above of= for newer above= of (needs positioning library, page 229).

By the way, please, consider to change from \tikzstyle to \tikzset syntax: Should \tikzset or \tikzstyle be used to define TikZ styles?

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

enter image description here

Ignasi
  • 136,588