3

Is it possible to make something like this:enter image description here

The best thing I could do was this:

enter image description here With this code:

\documentclass[symmetric,justified,a4paper]{tufte-book} 
\usepackage[utf8]{inputenc} 
\usepackage[decimalsymbol=comma,per-mode=fraction,exponent-product = \cdot]{siunitx}
\sisetup{load-configurations = abbreviations}
\usepackage{pgf,tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,arrows}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{mathtools}
\begin{document}
        \begin{center}
        \begin{tikzpicture}[scale=0.75]
        \tkzInit[ymin=-0.6,ymax=6, xmin=0,xmax=14]
        \tkzClip
        %\tkzGrid
        \tkzDefPoints{2/3/A, 4/3/B, 9/3/C, 11/3/D, 6/2/E, 8/2/F};
        \draw [very thick] (0,0) -- (14,0);
        \draw [<->,dashed] (0,5.2) -- (7,5.2) node[pos=0.5,above] {$\Delta x=\SI{5,0}{m}$} ;
        \draw [fill=black!20] (0,0.2) rectangle (2,4.8);
        \draw [fill=black!20] (7,0.2) rectangle (9,4.8);
        \draw [->, ultra thick] (A) -- (B) node[pos=0.5,above] {$F=\SI{50}{\N}$};
        \draw [->, ultra thick] (C) -- (D) node[pos=0.5,above] {$F=\SI{50}{\N}$};
        \draw [fill,pattern=north east lines,draw=none] (0,0) rectangle (14,-0.5);
        \draw [thick,red] plot [smooth] coordinates { (0,0) (2,0) (6,5) (7,0) (10,4) (14,0)};

        \end{tikzpicture}
        \end{center}
\end{document}

So my questions is can I make the red box with the kid once and translate it on the path (and also make the path better looking). The rollercoaster square pattern would be nice, but is not a must.

1
2

Here's my attempt: enter image description here

I had to change some values, e.g. the distance between the gray rectangles, in order to have enough space. To better approximate the rollercoaster path you can use .. controls () and () .. or [out=<angle OUT>,in=<angle IN>]; I tried with the latter, even if with controls one is able to define complex paths more easily (but spending much more time trying to define all the control points).

To define the style for the kid on the wagon I adapted Gonzalo Medina's code from "Straight line in TikZ with 'continued' marking in the middle". Unfortunately, I wasn't able to rotate the node automatically according to the line's slope, but you only have to set the right value of rotate=.. and if the node has to be right or above and so on.

As for the rollercoaster grid, I simply used the same rollercoaster's path to clip a grid as big as the picture.

\documentclass[symmetric,justified,a4paper]{tufte-book}
\usepackage[utf8]{inputenc} 
\usepackage[decimalsymbol=comma,per-mode=fraction,exponent-product = \cdot]{siunitx}
\sisetup{load-configurations = abbreviations}
\usepackage{pgf,tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,arrows}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{mathtools}

\def\WagonW{7.5pt}
\def\WagonH{5pt}
\def\KidHead{2pt}
\tikzset{
  Kid/.style={
    postaction={decorate,
      decoration={
        markings,
        mark=at position #1 with
          {
              \draw[red,fill=red] (0pt,0pt) rectangle (\WagonW,\WagonH);
              \draw[black,fill=black] (3.5pt,8pt) circle (\KidHead);
              \draw[-,black,thick] (3.5pt,5.5pt) -- (-2pt,7pt);
              \draw[-,black,thick] (3.5pt,5.5pt) -- (8.5pt,7pt);
          }
       }
    }
  },
  Kid/.default={0.5}
}
\begin{document}
        \begin{tikzpicture}[scale=0.75]
        \tkzInit[ymin=-0.6,ymax=6, xmin=0,xmax=17]
        \tkzClip
        %\tkzGrid
        \tkzDefPoints{2/3.5/A, 4/3.5/B, 12/3.5/C, 14/3.5/D, 6/2/E, 8/2/F};

        \draw [very thick] (0,0) -- (17,0);
        \draw [<->,dashed] (0,5.2) -- (10,5.2) node[pos=0.5,above] {$\Delta x=\SI{5,0}{m}$};
        \draw [fill=black!20] (0,0.2) rectangle (2,4.8);
        \draw [fill=black!20] (10,0.2) rectangle (12,4.8);

        \draw [fill,pattern=north east lines,draw=none,name path=ground] (0,0) rectangle (17,-0.5);
        \draw [thick,red,name path=rollercoaster] (0,0) -- (2,0)  to [out=0,in=180]  (6,5) to [out=0,in=180] node[pos=0.1,rotate=50,right,Kid]{} node[rotate=20,right,Kid]{} (10,0) to [out=0,in=180] (14,3.5) to [out=0,in=180] node[pos=0,rotate=80,right,Kid]{} (17,0);

        \draw [->, ultra thick] (A) -- (B) node[pos=0.5,above] {$F=\SI{50}{\N}$};
        \draw [->, ultra thick] (C) -- (D) node[pos=0.5,above] {$F=\SI{50}{\N}$};

        \path[clip] (0,0) -- (2,0)  to [out=0,in=180]  (6,5) to [out=0,in=180] (10,0) to [out=0,in=180] (14,3.5) to [out=0,in=180] (17,0);
        \draw[red,step=0.5cm] (0,0) grid (17,8);
        \end{tikzpicture}
\end{document}
1
  • 1
    Trying to understand the code, and having more controle over the little kids (before they get sick) – Arne Timperman Aug 25 '15 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.