What is the easiest way to sketch a sinusoidal wave in PGF/Tikz? I have tried this:
\begin{tikzpicture}
\draw[loosely dotted] (0,0) grid (4,2);
\draw[x=0.5cm,y=1cm, ultra thick, red]
(0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1) cos (5,0) sin (6,-1);
\end{tikzpicture}
How do I get the grid to cover all the wave? Is there a better way of sketching (not plotting) functions/waves?
Best Answer
As I said in my comment, you can adjust the grid by choosing the coordinates on the line with
grid
in it:Your second
\draw
line changes the scale of the x axis to0.5cm
instead of1cm
as is the default. So(3,1)
on the first line is the same point as(6,1)
on the second line.If you just want to interpolate points on a curve smoothly, you can use the
plot
command of tikz like so:There is a
tension
key that adjusts the curviness of the smoothing but frankly I couldn't get anything that looked better to me than the default.Another option would be to use Bézier curves. However, in specifying a Bézier curve between two points, two additional points are needed. These two describe the velocity vector coming out of and into each point.
You'll notice I took advantage of the symmetry to eliminate the coordinates along the $x$-axis.