3

I don't understand what's going on here. If the domain of the parametric parameter \t is 0:100, then the function sin(2pi*t) should oscillate about 100 times, but it only oscillates a couple. What am I missing?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[x=.6\textwidth,y=.6\textwidth]
    \draw[very thin,color=gray, step=.1] (0.0,0.0) grid (1,1);
    \draw [ thick,  domain=0:100, samples=40, smooth, variable=\t] 
    plot ({\t/100}, {sin(2*pi*\t)*.5+.5});
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

5

You got the domain right. The problem is that the trigonometric functions in TikZ are (oddly, in my opinion) in degrees by default. So 2*pi*\t with \t between 0 and 100 will give you the sine function (in degrees) between 0 and 628.3 degrees (which is about 10.96 radians) which almost 1.75 periods of the function. This is exactly what you see there: one full period and 3/4 of another.

You can tell TikZ to use radians by appending an r to the argument or using the rad function (see page 1005 of the TikZ-PGF manual, section 93.3.4 “Trigonometric functions”). I also added the FPU to allow the domain up to 100 and increased the number of samples to 400 following Kpym's suggestion (notice the aliasing):

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[x=.6\textwidth,y=.6\textwidth]
    \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
    \draw[very thin,color=gray, step=.1] (0.0,0.0) grid (1,1);
    \draw [ thick,  domain=0:100, samples=400, smooth, variable=\t]
    plot ({\t/100}, {sin(2*pi*\t r)*.5+.5});
  \end{scope}%                   ^
\end{tikzpicture}
\end{document}
  • 1
    with samples=400,smooth it looks better, but this is not the question ;) – Kpym Mar 15 at 22:08
  • @Kpym Certainly! I just removed the smooth to show that 100 cycles with 40 samples won't do (unless OP wants to show the aliasing). Thanks anyway :) – Phelype Oleinik Mar 15 at 22:11
  • Doh! Degrees... Yeah, don't know why that didn't occur to me. I'm just so used to thinking in radians. Usually trigonometric functions are defined assuming radians, but I guess it makes sense since everywhere else in latex assumes angles are degrees. I actually did try and turn up the samples at first - thought it was just aliasing. – argentum2f Mar 15 at 23:14
  • @argentum2f Yes, as I said “oddly”. All programming languages I know (which aren't that many, but...) have a sin function for argument radians and sind function for argument in degrees. Anyhow, Till must have had his reasons :) – Phelype Oleinik Mar 15 at 23:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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