6

How could I express this diagram (attached) as a TikZ picture to be used in a LaTeX document? I've been working on it for a while with no success.

Thank you for your help.

Diagram

\documentclass{article}% guessing (cfr)
\usepackage{tikz}
\usepackage[top=1in,bottom=1in,right=1in,left=1in]{geometry}
\begin{document}% added - surely necessary! (cfr)
\begin{tikzpicture}[scale=5.3,cap=round,>=latex]
        \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white] {$x$};
        \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white] {$y$};

        \draw[thick] (0cm,0cm) circle(1cm);

        \foreach \x in {0,30,...,360} {
                \draw[gray] (0cm,0cm) -- (\x:1cm);
                \filldraw[black] (\x:1cm) circle(0.4pt);
                \draw (\x:0.6cm) node[fill=white] {$\x^\circ$};
        }

        \foreach \x/\xtext in {
            30/\frac{\pi}{6},
            45/\frac{\pi}{4},
            60/\frac{\pi}{3},
            90/\frac{\pi}{2},
            120/\frac{2\pi}{3},
            135/\frac{3\pi}{4},
            150/\frac{5\pi}{6},
            180/\pi,
            210/\frac{7\pi}{6},
            225/\frac{5\pi}{4},
            240/\frac{4\pi}{3},
            270/\frac{3\pi}{2},
            300/\frac{5\pi}{3},
            315/\frac{7\pi}{4},
            330/\frac{11\pi}{6},
            360/2\pi}
                \draw (\x:0.85cm) node[fill=white] {$\xtext$};

        \foreach \x/\xtext/\y in {
            30/\frac{\sqrt{3}}{2}/\frac{1}{2},
            45/\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            60/\frac{1}{2}/\frac{\sqrt{3}}{2},
            150/-\frac{\sqrt{3}}{2}/\frac{1}{2},
            135/-\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            120/-\frac{1}{2}/\frac{\sqrt{3}}{2},
            210/-\frac{\sqrt{3}}{2}/-\frac{1}{2},
            225/-\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            240/-\frac{1}{2}/-\frac{\sqrt{3}}{2},
            330/\frac{\sqrt{3}}{2}/-\frac{1}{2},
            315/\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            300/\frac{1}{2}/-\frac{\sqrt{3}}{2}}
                \draw (\x:1.25cm) node[fill=white] {$\left(\xtext,\y\right)$};

        \draw (-1.25cm,0cm) node[above=1pt] {$(-1,0)$}
              (1.25cm,0cm)  node[above=1pt] {$(1,0)$}
              (0cm,-1.25cm) node[fill=white] {$(0,-1)$}
              (0cm,1.25cm)  node[fill=white] {$(0,1)$};
    \end{tikzpicture}
\end{document}

Which came out as Unit circle image

  • Welcome to TeX SE! Please post an example showing what you've tried so that people have something to work with. Start with \documentclass{} and end with \end{document}. You can edit your question, paste the code and then format it by highlighting it and clicking the {} button. – cfr Mar 15 '15 at 00:08
  • Is this a duplicate of http://www.texample.net/tikz/examples/phasor-diagram/ and http://tex.stackexchange.com/questions/206936/how-to-animate-a-sine-curve-in-pstricks-tikz ? – percusse Mar 15 '15 at 00:17
  • I am not looking to animate it nor am I looking to use Gnuplot. –  Mar 15 '15 at 00:19
  • 2
    Please don't discard with haste. Gnuplot is not essential nor animation. The single frame from the animation is identical to what you have. – percusse Mar 15 '15 at 00:29
  • Thanks for adding your code. As it was, it wouldn't compile for sure. I've tried to complete it for you but please check to see I've not missed anything. (I didn't know what class you were using so I've guessed article.) I like the circle ;). – cfr Mar 15 '15 at 01:50
  • @percusse The first one does claim gnuplot is essential in the comments. Is that wrong? [It seems implausible as it is stated there - I'm assuming it means something like 'no way to do it by any simple modification of this code'.] – cfr Mar 15 '15 at 01:53
  • Thank you. I'm still trying and have been for a bit. (: I will check to see if there's anything's missing, which I doubt. (: –  Mar 15 '15 at 01:55
  • And yes, the class is article. :) –  Mar 15 '15 at 01:58

1 Answers1

5

A beginning, maybe.

EDIT This version combines the two pictures I used in the original version, and uses backgrounds to demonstrate how to add the dashed lines. Two such lines are drawn to illustrate the method. (It isn't terribly tidy but the lines do appear in the intended places.)

EDIT 2 This version draws more lines via a loop and adds the perpendiculars down to the x axis.

sine waves

\documentclass[a4paper]{article}% guessing (cfr)
\usepackage[landscape,scale=.9]{geometry}
\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions,backgrounds,calc}
\def\mytypesetter#1{% page 813
  \pgfmathparse{#1/pi}%
  \pgfmathprintnumber{\pgfmathresult}$\pi$%
}
\begin{document}% added - surely necessary! (cfr)
  \centering
  \begin{tikzpicture}[scale=4,cap=round,>=latex,baseline={(0,0)}]
    \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white] {$x$};
    \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white] {$y$};

    \draw[thick] (0cm,0cm) circle(1cm);

    \foreach \x in {0,30,...,360} {
      \draw[gray] (0cm,0cm) -- (\x:1cm);
      \filldraw[black] (\x:1cm) coordinate (x\x) circle (0.4pt);
      \draw (\x:0.6cm) node[fill=white] {$\x^\circ$};
    }

    \foreach \x/\xtext in {
      30/\frac{\pi}{6},
      45/\frac{\pi}{4},
      60/\frac{\pi}{3},
      90/\frac{\pi}{2},
      120/\frac{2\pi}{3},
      135/\frac{3\pi}{4},
      150/\frac{5\pi}{6},
      180/\pi,
      210/\frac{7\pi}{6},
      225/\frac{5\pi}{4},
      240/\frac{4\pi}{3},
      270/\frac{3\pi}{2},
      300/\frac{5\pi}{3},
      315/\frac{7\pi}{4},
      330/\frac{11\pi}{6},
      360/2\pi}
    \draw (\x:0.85cm) node[fill=white] {$\xtext$};

    \foreach \x/\xtext/\y in {
      30/\frac{\sqrt{3}}{2}/\frac{1}{2},
      45/\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
      60/\frac{1}{2}/\frac{\sqrt{3}}{2},
      150/-\frac{\sqrt{3}}{2}/\frac{1}{2},
      135/-\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
      120/-\frac{1}{2}/\frac{\sqrt{3}}{2},
      210/-\frac{\sqrt{3}}{2}/-\frac{1}{2},
      225/-\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
      240/-\frac{1}{2}/-\frac{\sqrt{3}}{2},
      330/\frac{\sqrt{3}}{2}/-\frac{1}{2},
      315/\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
      300/\frac{1}{2}/-\frac{\sqrt{3}}{2}}
    \draw (\x:1.25cm) node {$\left(\xtext,\y\right)$};

    \draw (-1.25cm,0cm) node[above=1pt] {$(-1,0)$}
    (1.25cm,0cm)  node[above=1pt] {$(1,0)$}
    (0cm,-1.25cm) node[fill=white] {$(0,-1)$}
    (0cm,1.25cm)  node[fill=white] {$(0,1)$};
    \begin{scope}[xshift=20mm]
      \datavisualization
      [
      school book axes,
      y axis={unit length=10mm},
      x axis={unit length=2.5mm, ticks={step=(.5*pi), tick typesetter/.code=\mytypesetter{##1}}},
      visualize as smooth line,
      ]
      data [format=function] {
        var x : interval [0:4*pi];
        func y = sin(\value x r);
      };
    \end{scope}
    \begin{scope}[on background layer]
      \coordinate (o) at (0,0);
      \foreach \i in {90,120,...,270}
        {
          \draw [densely dashed, opacity=.25, color=blue!50!cyan] (x\i) -- ({x\i} -| o) -- ++(20mm,0) -- ++(pi*\i/720,0) coordinate (xx\i) edge (xx\i |- o)  -- ++(.5*pi,0) coordinate (xxx\i) edge (xxx\i |- o);
        }
    \end{scope}
  \end{tikzpicture}
\end{document}
cfr
  • 198,882
  • Nice! I just need to figure out how to do the dashed lines connecting the two... (: I'll go ahead and edit it so that the radians are in fractional form rather than in decimal. –  Mar 15 '15 at 03:47
  • We would also need the Y axis in the sine graph to extend to (0,1) and (0,-1) relative to the unit circle so they can connect. –  Mar 15 '15 at 17:09
  • @SinTheta Just change the unit length to whatever you need. – cfr Mar 15 '15 at 19:46
  • How do I add the dashed lines connecting the values on the circle to the values on the graph? –  Mar 15 '15 at 20:13
  • @SinTheta See edited version above. You can use the backgrounds library to draw the lines but you need to combine the two tikzpicture environments. I've drawn 2 of the lines to illustrate the idea. – cfr Mar 15 '15 at 23:31
  • Hmm, nice, but still confused. –  Mar 16 '15 at 04:50
  • @SinTheta Just generally? Or about something in particular? – cfr Mar 16 '15 at 13:45
  • The lines. They are confusing. Would you mind filling the rest in? And there's no way that I can scale it smaller without ruining my unit circle? –  Mar 16 '15 at 16:25
  • @SinTheta Probably easiest is if you name the nodes where you draw the black circles and then use those points as the start of the lines. The *.25 is just because I used a unit length of 2.5mm which is a quarter of a standard unit, and the 20mm addition is the x shift of the right hand part of the diagram. I'm not sure what you mean about scaling? – cfr Mar 16 '15 at 16:34
  • When I scale down the TikZ picture it gets messed up. Illegible. –  Mar 16 '15 at 16:44
  • @SinTheta Have you tried using a smaller font? The labels won't fit otherwise if you scale it down too much. – cfr Mar 16 '15 at 17:44
  • @SinTheta See edit. I've added a loop to draw some lines. The idea is the same as before. I tried scaling it down and it works OK if you change the font size. But I think it becomes unhelpfully small at that point. If you need it smaller, I guess think about simplifying it. Otherwise, rotate the figure so you can fit it on the page. – cfr Mar 18 '15 at 00:40
  • Is it possible to show two functions at the same time? Like a sin(x) and a cos(x)? – Rodrigo Nov 12 '19 at 20:11
  • @Rodrigo Yes, but it might not be very useful. At least the left part of the diagram wouldn't make much sense, though the right should be fine. Just add the second to the same diagram, I guess. – cfr Nov 12 '19 at 23:13