1

I need to plot the main 6 trigonometric functions in an animated manner similar to the one shown in Draw an animated gif of trigonometry function

However,

  • I need the circle to be the same one shown here: https://texample.net/tikz/examples/unit-circle/ where the values used for each curve are to be highlighted (When using the sign curve, highlight the values for sign curve on the circle .... and so on)

  • I need the curve for the wave to be similar to the one shown in How to animate a sine curve in PStricks/Tikz (But Angles are to be in radians and degrees, highlight each 2 equivalent angles on the curve and the circle in animation, also need to show period length...)

  • Need also a seventh graph to plot sine and cosine curve overlapping with different colors to emphasize them.

  • Need to emphasize all possible details.

I have included the drawing and a previously proposed animation code in a previous post (MWE) as a starting point, yet it is a bit overwhelming to modify it and include all the details.


\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz} \usetikzlibrary{arrows.meta,arrows,positioning,matrix,quotes, shapes.geometric,calc,decorations.markings,decorations.pathmorphing, backgrounds,graphs,shapes,shapes.misc,fit,angles,quotes,datavisualization.formats.functions,intersections,hobby}

\usepackage[bidi=basic,layout=lists.tabular]{babel} \babelprovide[import=en,maparabic,main]{english} \babelfont[english]{rm}{Times New Roman}

\begin{document}

\begin{figure}[!htbp] \begin{center} \begin{tikzpicture}[scale=5.3,cap=round,>=latex] % draw the coordinates \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 the unit circle
    \draw[thick] (0cm,0cm) circle(1cm);

    \foreach \x in {0,30,...,360} {
            % lines from center to point
            \draw[gray] (0cm,0cm) -- (\x:1cm);
            % dots at each point
            \filldraw[black] (\x:1cm) circle(0.4pt);
            % draw each angle in degrees
            \draw (\x:0.6cm) node[fill=white] {$\x^\circ$};
    }

    % draw each angle in radians
    \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 {
        % the coordinates for the first quadrant
        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},
        % the coordinates for the second quadrant
        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},
        % the coordinates for the third quadrant
        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},
        % the coordinates for the fourth quadrant
        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 the horizontal and vertical coordinates
    % the placement is better this way
    \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{center} \caption {Circle} \label{fig:angle} \end{figure}

\foreach \angle in {0,10,...,360} { \begin{tikzpicture} % fill circle and plot \fill[blue!50] (-1,0) arc (0:\angle:1) -- (-2,0) -- cycle; \fill[blue!50] plot[smooth,domain=0:\angle] (pi/180\x,{sin(\x)}) |- (0,0); % draw connection \draw (-2,0) +(\angle:1) circle (2pt) -- (pi/180\angle,{sin(\angle)}) circle (2pt); % draw axes an ticks \draw (-3.5,0) -- (7,0); \foreach \deg in {90, 180, 270, 360} \draw (pi/180\deg,2pt) -- (pi/180\deg,-2pt) node[below] {$\deg^\circ$}; \draw (0,-1.2) -- (0,1.2); \foreach \y in {-1,-0.5,0.5,1} \draw (2pt,\y) -- (-2pt,\y) node[left] {$\y$}; % draw plot and circle outline \draw plot[smooth,domain=0:360] (pi/180*\x,{sin(\x)}); \draw (-2,0) circle (1); \end{tikzpicture} } \end{document}

Alenanno
  • 37,338
Silva
  • 743
  • The code you provided generates errors. Copying it from somewhere else is fine, but you should test it on your machine so that it works as is. I saw Overfull \hbox errors, or broken references, but even before trying it I could see the library count being way too high for a code this short. – Alenanno Oct 25 '20 at 23:30
  • @Alenanno, the code is working fine on my system. Did you run it using Lualatex? – Silva Oct 26 '20 at 15:34
  • Ah yes, now it does. I added the relevant tag. – Alenanno Oct 26 '20 at 17:05

1 Answers1

2

You need more however but your code is not the closest related to the desired result.

A version with Asymptote.

import animate;
import graph;
settings.tex="pdflatex"; 
animation Ani;
size(500);

transform t(real x=0){ return shift((-5,x))scale(3); } transform t=t(); transform labelscale=scale(.6); transform t1=shift((1.5,0))scale(2,3);

string[][] s={ {"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"} }; int[] a={30,45,60,150,135,120,210,225,240,330,315,300}; string[][] z={ // the coordinates for the first quadrant {"\frac{\sqrt{3}}{2}","\frac{1}{2}"}, {"\frac{\sqrt{2}}{2}","\frac{\sqrt{2}}{2}"}, {"\frac{1}{2}","\frac{\sqrt{3}}{2}"}, // the coordinates for the second quadrant {"-\frac{\sqrt{3}}{2}","\frac{1}{2}"}, {"-\frac{\sqrt{2}}{2}","\frac{\sqrt{2}}{2}"}, {"-\frac{1}{2}","\frac{\sqrt{3}}{2}"}, // the coordinates for the third quadrant {"-\frac{\sqrt{3}}{2}","-\frac{1}{2}"}, {"-\frac{\sqrt{2}}{2}","-\frac{\sqrt{2}}{2}"}, {"-\frac{1}{2}","-\frac{\sqrt{3}}{2}"}, // the coordinates for the fourth quadrant {"\frac{\sqrt{3}}{2}","-\frac{1}{2}"}, {"\frac{\sqrt{2}}{2}","-\frac{\sqrt{2}}{2}"}, {"\frac{1}{2}","-\frac{\sqrt{3}}{2}"} }; string[] q={ "90^\circ(\frac{\pi}{2})", "180^\circ(\pi)", "270^\circ(\frac{3\pi}{2})", "360^\circ(2\pi)", }; real[] m={pi/2,pi,3pi/2,2pi};

for (int j=0; j <= 360; j=j+5){ save(); // sin(x) if(j != 0) { fill(t*((0,0)--arc((0,0),1,0,j)--cycle),blue+opacity(.4)); }

draw(Label("$x$",EndPoint,filltype=Fill(white)),t((-1.5,0)--(1.5,0)),Arrow); draw(Label("$y$",EndPoint,filltype=Fill(white)),t((0,-1.5)--(0,1.5)),Arrow);

draw(t*circle((0,0),1));

for (int i=0; i<= 360; i=i+30) { draw(t((0,0)--dir(i)),gray); dot(tdir(i),linewidth(1.5bp)); if(i != 0) label(labelscaleLabel(format("$%d^\circ$",i),filltype=Fill(invisible)), t(0.6*dir(i))); }

for (int i=0; i<s.length; ++i) { label(labelscaleLabel("$"+s[i][1]+"$",filltype=Fill(invisible)), t(0.85dir((int) s[i][0]))); } for (int i=0; i<a.length; ++i) { label(labelscaleLabel("$("+z[i][0]+","+z[i][1]+")$",filltype=Fill(invisible)), t(1.3dir(a[i]))); } label(labelscale"$(-1,0)$",t(-1.25,0),dir(90)); label(labelscale"$(1,0)$",t(1.25,0),dir(90)); label(labelscale"$(0,-1)$",t(0,-1.25),Fill(white)); label(labelscale"$(0,1)$",t(0,1.25),Fill(white)); //************************ draw(scale(.8)Label("$x$",EndPoint),t1((0,0)--(2pi+0.5,0)),Arrow); draw(scale(.8)Label("$y=\sin(t)$",EndPoint),t1((0,-1.5)--(0,1.5)),Arrow); for (real a : new real[]{-1,-0.5,0.5,1}) { draw(scale(0.6)Label("$"+(string) a+"$",Relative(0)),t1*((0,a)-(0.1,0)--(0,a)+(0.1,0))); }

for (int i=0; i< q.length; ++i) { draw(scale(0.6)Label("$"+q[i]+"$",Relative(0),Fill(invisible)), t1((m[i],0)-(0,0.03)--(m[i],0)+(0,0.03))); }

real f(real x){return sin(x);} guide F=graph(f,0,2pi,300); fill(t1((0,0)--graph(f,0,radians(j),300)--(radians(j),0)--cycle),blue+opacity(.4)); draw(t1F,blue); draw(tdir(j)--t1(radians(j),f(radians(j))),(j!=0) ? currentpen : invisible); draw(t1(radians(j),f(radians(j)))--t1(radians(j),0),black+0.4bp); dot(tdir(j),Fill(white)); dot(t1*(radians(j),f(radians(j))),Fill(white));

label(Label("Length"+"$="+(string) arclength(graph(f,0,radians(j),1000))+"$"),t1(4,-2)); label(Label("Length"+"$="+(string) arclength((j!=0) ? Arc((0,0),1,0,j) : nullpath)+"$"), t(0,-2));

Ani.add(); restore(); draw(t1(radians(j),f(radians(j)))--t1(radians(j),0),black+0.4bp); } erase(); Ani.movie(BBox(2mm,invisible));

enter image description here