0

What I'm looking for

I am using TikZ to create a cheatsheet that is intended to be used for practicing handwriting. I want to use sine waves as a pattern for practicing handwriting, so I want to display horizontal and vertical sine waves in the same page. In the cheatsheet I am creating, I want to draw a group of horizontal sine waves that go from one end of the sheet to the other end and that are very close. Below that group, I want to draw a group of vertical sine waves. I created the following graphic using Inkscape to show what I'm looking for.

enter image description here

What I've tried

I know how to draw horizontal sine waves using TikZ. See minimal working example below.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw[opacity=0.2] (0,0) grid (10,2);
  \draw[red]  (0,1) sin (1, 2);
  \draw[blue] (1,2) cos (2, 1);
  \draw[red]  (2,1) sin (3, 0);
  \draw[blue] (3,0) cos (4, 1);
  \draw[red]  (4,1) sin (5, 2);
  \draw[blue] (5,2) cos (6, 1);
  \draw[red]  (6,1) sin (7, 0);
  \draw[blue] (7,0) cos (8, 1);
  \draw[red]  (8,1) sin (9, 2);
  \draw[blue] (9,2) cos (10,1);
\end{tikzpicture}
\end{document}

enter image description here

In order to create a vertical sine wave I tried using sin and cos and specify coordinates one after the other. However, given the nature of sin and cos functions, this doesn't look as smooth as the first graphic.

%% This file is intended to be compiled by executing the following
%% commands:
%% $ pdflatex main

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw[opacity=0.2] (0,2) grid (10,-10);
  % Horizontal sine wave
  \draw[red]  (0,1) sin (1, 2);
  \draw[blue] (1,2) cos (2, 1);
  \draw[red]  (2,1) sin (3, 0);
  \draw[blue] (3,0) cos (4, 1);
  \draw[red]  (4,1) sin (5, 2);
  \draw[blue] (5,2) cos (6, 1);
  \draw[red]  (6,1) sin (7, 0);
  \draw[blue] (7,0) cos (8, 1);
  \draw[red]  (8,1) sin (9, 2);
  \draw[blue] (9,2) cos (10,1);
  % My attempt to draw a vertical sine wave (the result is not a
  % vertical sine wave)
  \draw[red]  (1,-0) cos  (2,-1);
  \draw[blue] (2,-1) sin  (1,-2);
  \draw[red]  (1,-2) cos  (0,-3);
  \draw[blue] (0,-3) sin  (1,-4);
  \draw[red]  (1,-4) cos  (2,-5);
  \draw[blue] (2,-5) sin  (1,-6);
  \draw[red]  (1,-6) cos  (0,-7);
  \draw[blue] (0,-7) sin  (1,-8);
  \draw[red]  (1,-8) cos  (2,-9);
  \draw[blue] (2,-9) sin  (1,-10);
\end{tikzpicture}
\end{document}

enter image description here

The question

How to display a vertical sine wave below an horizontal sine wave in the same tikzpicture environment?

The answer doesn't need to be the code for the first graphic, which I created using Inkscape, shown above. A vertical sine wave below an horizontal sine wave in the same tikzpicture environment would be enough.

3
  • 1
    What you have drawn on the tikz graph is not sine rotated 90 degrees.
    – LdBeth
    Commented Feb 29 at 2:34
  • @LdBeth Thanks for pointing that out. I have edited the comment in my post from % Vertical sine wave to % My attempt to draw a vertical sine wave (the result is not a % vertical sine wave) Commented Feb 29 at 3:20
  • You can create a parametric plot where x=sin(\t) and y=\t (see pgf manual page 345 or pgfplots manual page 56). Commented Feb 29 at 4:29

1 Answer 1

2

Have you considered rotating a horizontal sine wave?

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw[opacity=0.2] (0,2) grid (10,-10);
  % Horizontal sine wave
  \draw[red]  (0,1) sin (1, 2);
  \draw[blue] (1,2) cos (2, 1);
  \draw[red]  (2,1) sin (3, 0);
  \draw[blue] (3,0) cos (4, 1);
  \draw[red]  (4,1) sin (5, 2);
  \draw[blue] (5,2) cos (6, 1);
  \draw[red]  (6,1) sin (7, 0);
  \draw[blue] (7,0) cos (8, 1);
  \draw[red]  (8,1) sin (9, 2);
  \draw[blue] (9,2) cos (10,1);
  % Vertical sine wave; draw horizontal & rotate
  \draw[red, rotate around={-90:(1.5,-1)}]  (0,-1) sin (1, -2);
  \draw[blue, rotate around={-90:(1.5,-1)}] (1,-2) cos (2, -1);
  \draw[red, rotate around={-90:(1.5,-1)}]  (2,-1) sin (3, -0);
  \draw[blue, rotate around={-90:(1.5,-1)}] (3,-0) cos (4, -1);
  \draw[red, rotate around={-90:(1.5,-1)}]  (4,-1) sin (5, -2);
  \draw[blue, rotate around={-90:(1.5,-1)}] (5,-2) cos (6, -1);
  \draw[red, rotate around={-90:(1.5,-1)}]  (6,-1) sin (7, -0);
  \draw[blue, rotate around={-90:(1.5,-1)}] (7,-0) cos (8, -1);
  \draw[red, rotate around={-90:(1.5,-1)}]  (8,-1) sin (9, -2);
  \draw[blue, rotate around={-90:(1.5,-1)}] (9,-2) cos (10,-1); 
\end{tikzpicture}
\end{document}

You also can just use a function to capture them.

\begin{document}
    \begin{tikzpicture}
        \draw[opacity=0.2] (0,2) grid (10,-10);
        \draw[domain=0:10, smooth, samples=100, thick, red] plot (\x, {sin(pi/2 
        * \x r) + 1}); 
        \draw[domain=0:10, smooth, samples=100, thick, blue] plot ({sin(pi/2 * \x r) + 1}, -\x);

    \end{tikzpicture}
\end{document}

Output:

enter image description here

And going further, if you want to make many of these, I recommend you create a function which takes in an input of starting point, and horizontal/vertical length, which creates the sin wave along it.

3
  • Thanks. That's what I was looking for. With regards to defining a function which takes in an input, I have never defined a function in TikZ and I don't know how to do it. I searched a bit on the Internet and came across with n args (as explained in this answer.) which I have never used either. Is using n args what you mean with creating a function or you meant other way of defining functions in TikZ? Commented Feb 29 at 3:15
  • I just meant use \newcommand to expand the command into the sine wave.
    – user206144
    Commented Feb 29 at 3:28
  • 1
    Or use Tikz‘ \pic.
    – MS-SPO
    Commented Feb 29 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .