Here's eight full oscillations of a sine wave:
Here's the code:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[gray!20] (0,-2) grid (32,2); %Grid
\draw[black,-] (0, 0) -- (32,0); %X-Axis
\draw[black,-] (0,-2) -- (0 ,2); %Y-Axis
\draw[blue] (0 ,0) %Origin
%Sine-Wave%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sin (1 ,2) cos (2 ,0) sin (3 ,-2) cos (4 ,0) sin (5 ,2) cos (6 ,0) sin (7 ,-2) cos (8 ,0)
sin (9 ,2) cos (10,0) sin (11,-2) cos (12,0) sin (13,2) cos (14,0) sin (15,-2) cos (16,0)
sin (17,2) cos (18,0) sin (19,-2) cos (20,0) sin (21,2) cos (22,0) sin (23,-2) cos (24,0)
sin (25,2) cos (26,0) sin (27,-2) cos (28,0) sin (29,2) cos (30,0) sin (31,-2) cos (32,0);
\end{tikzpicture}
\end{document}
My question isn't necessarily about sine waves or trigonometric functions. It's more about writing algorithms with LaTeX and using it like a real programming language.
Notice how I manually specified 32 pairs of coordinates and referred to both sin
& cos
16 times just to draw 8 iterations of the same curve? Say, I want to generate a series of different standalone waves that are similar but different to this one. I don't want to have to type in every single coordinate every time, I want to automate all the boring, repetitive stuff.
Now, I don't need somebody to just draw it for me and dump the code, but rather share and explain the different tricks & techniques you can use to solve it in a programmatic way. A lot of us aren't aware of the tools at our disposal. The goal is to show the rest of us how to approach and solve these problems on our own so we can learn to do it for ourselves.
for
loops?