Anzeige:
Ergebnis 1 bis 3 von 3

Thema: Sinuskurve mit Animate erscheinen lassen.

  1. #1
    Registrierter Benutzer
    Registriert seit
    27.11.2005
    Beiträge
    90

    Sinuskurve mit Animate erscheinen lassen.

    Moin zusammen,

    Gibt es einen eleganteren Weg, die Sinuskurve im unteren Bereich zu animieren? Tue mir mit dem Plotten von Funktionen welche nicht im Ursprung beginnen noch immer schwer.

    Hab einen Teil vom Code durch Recherche gefunden und angepasst. Habe an zwei Stellen einen Kommentar hinterlassen, wo ich nicht genau verstehe was geschieht.

    Schon mal vielen Dank für hilfreiche Tipps!

    Grüße

    Code:
    \documentclass[	paper=a4,
                    twocolumn=false,
    				captions=tableheading,
                    oneside,
                    BCOR = 12mm,
                    %14pt,
                    toc=listof,
                    toc=index,
                    toc=bibliography,
                    %landscape,
                    %openright,
                    pointlessnumbers,
                    DIV=15
                    ]
    				{scrbook}
    
    \usepackage[ansinew]{inputenc}
    \usepackage[table,xcdraw,dvipsnames]{xcolor}
    \usepackage{tikz}
    \usepackage{hyperref}
    \usepackage{ifthen}
    \usepackage{animate}
    
    \newcounter{angle}
    \setcounter{angle}{0}
    
    \begin{document}
    
    \begin{center}
        \begin{animateinline}[loop, poster = first, controls]{30}
        
        \whiledo{\theangle<359}{
            \begin{tikzpicture}
                %\draw[step=0.1cm,black!20!white,very thin] (-3,-10) grid++ (6,8);
                %\draw[step=0.5cm,black!20!white,] (-3,-10) grid++ (6,8);
                \draw (-3,-10) rectangle (4,3);
                
                \draw[thick,->] (-2,0)--(2,0) node[below] {$x$}; 
                \draw[thick,->] (0,-2)--(0,2) node[left] {$y$}; 
                \draw[red,thick] (0,0) circle (1.5cm);
                \node[red,below] at (1.6,0) {1};
                \node[red,above] at (0.1,-1.5) {1};
                %
                \draw[ultra thick,cyan] (0,0) -- (0,0 |- \theangle:1.5cm); % Was geschied hier?
                \draw[ultra thick,orange] (0,0) -- (\theangle:1.5cm |- 0,0); % Was geschied hier?
                %
                \draw[densely dotted,orange] (\theangle:1.5cm) -- (\theangle:1.5cm |- 0,0); 
                \draw[densely dotted,cyan] (\theangle:1.5cm) -- (0,0 |- \theangle:1.5cm); 
                \draw[ultra thick,red,->,rotate=\theangle] (0,0) -- (1.5,0); 
            
                \draw[->] (0.5,0)  arc [start angle=0, delta angle=\theangle, radius=0.5cm];
                \draw (0.75,0.25) node[anchor= south west]{$\;\varphi = \omega t + \varphi_0$};
            
                \draw[red,orange] (2,1) node {\theangle};
                \fill[black] (0,0) circle (1mm);
            
                \draw (1.5,-2.5) circle (0.5mm);
            
                \draw[rotate=-90,xshift=2.5cm,yshift=1.5cm] (0,0) cos++ (1.5,-1.5) sin++ (1.5,-1.5) cos++(1.5,1.5) sin++(1.5,1.5);
                
                \ifthenelse{\theangle>21}{
                    \draw (1.5,-2.5) circle (0.5mm);
                };
                \ifthenelse{\theangle>20}{
                    \draw (1.4,-2.85) circle (0.5mm);
                };
                \ifthenelse{\theangle>29}{
                    \draw (1.3,-3.) circle (0.5mm);
                };
                \ifthenelse{\theangle>36}{
                    \draw (1.2,-3.12) circle (0.5mm);
                };
                \ifthenelse{\theangle>42}{
                    \draw (1.1,-3.22) circle (0.5mm);
                };
                \ifthenelse{\theangle>47}{
                    \draw (1.,-3.3) circle (0.5mm);
                };
                \ifthenelse{\theangle>52}{
                    \draw (0.9,-3.37) circle (0.5mm);
                };
                \ifthenelse{\theangle>57}{
                    \draw (0.8,-3.47) circle (0.5mm);
                };
                \ifthenelse{\theangle>61}{
                    \draw (0.7,-3.53) circle (0.5mm);
                };
                \ifthenelse{\theangle>65}{
                    \draw (0.6,-3.605) circle (0.5mm) ;
                };
                \ifthenelse{\theangle>69}{
                    \draw (0.5,-3.67) circle (0.5mm);
                };
                \ifthenelse{\theangle>74}{
                    \draw (0.4,-3.74) circle (0.5mm);
                };
                \ifthenelse{\theangle>78}{
                    \draw (0.3,-3.8) circle (0.5mm);
                };
                \ifthenelse{\theangle>81}{
                    \draw (.2,-3.87) circle (0.5mm);
                };
                \ifthenelse{\theangle>85}{
                    \draw (.1,-3.93) circle (0.5mm);
                };
                \ifthenelse{\theangle>89}{
                    \draw (0,-4.0) circle (0.5mm);
                };
                \ifthenelse{\theangle>93}{
                    \draw (-.1,-4.07) circle (0.5mm);
                };
                \ifthenelse{\theangle>97}{
                    \draw (-.2,-4.13) circle (0.5mm)node[below]{18};
                };
            \end{tikzpicture}
            
            \stepcounter{angle}
            
            \ifthenelse{\theangle<359}{
                    \newframe
            }{
                    \end{animateinline}
            }
        }
        \end{center}
    \end{document}

  2. #2
    Registrierter Benutzer Avatar von rais
    Registriert seit
    18.07.2005
    Beiträge
    5.862
    Moin moin,
    eine Sinuskurve würde ich rechts neben den Einheitskreis anordnen, dann kannst Du direkt rüberpeilen.
    Bevor ich mich an eine Animation machen würde, würde ich mir erstmal ein Beispiel rausziehen, quasi ein Standbild erzeugen und schauen, ob da alles soweit passt.
    BTW: \ithenelse hast Du falsch angewendet, der erwartet 3 Parameter: Bedingung, dann, sonst. Für `sonst' greift sich \ifthenelse hier das darauffolgende Semikolon (was dann auch versucht wird, ausgegeben zu werden).

    Die Intersections-Bibliothek könnte helfen, hier mal so ein `Standbild':
    Code:
    \documentclass[tikz]{standalone}
    
    \usetikzlibrary{intersections}
    
    \newcounter{angle}
    \setcounter{angle}{30}
    \newlength\xperdeg
    \setlength\xperdeg{0.166667mm}% Breite der Sinuskurve / Vollkreis (6cm/360°)
    
    \begin{document}
      \begin{tikzpicture}
        \draw[black!20] (0,1.5) -- +(4.5,0) %Projektierungslinien
          (0,-1.5) -- +(7.5,0)
          (2,0) -- (3,0);
        \draw[thick,->] (-2,0)--(2,0) node[below] {$x$}; 
        \draw[thick,->] (0,-2)--(0,2) node[left] {$y$};
        \draw[red,thick] (0,0) circle (1.5cm);
        \draw (1.6,0) node[red, below]{1};
        \draw (0,1.65) node[red,left]{1};
    %
        \draw[ultra thick,cyan] (0,0) -- (0,0 |- \theangle:1.5cm); % Siehe `texdoc pgfmanual', Abschnitt ``Intersections of Perpendicular Lines''
        \draw[ultra thick,orange] (0,0) -- (\theangle:1.5cm |- 0,0);
    %
        \draw[densely dotted,orange] (\theangle:1.5cm) -- (\theangle:1.5cm |- 0,0); 
        \draw[densely dotted,cyan] (\theangle:1.5cm) -- (0,0 |- \theangle:1.5cm); 
        \draw[ultra thick,red,->,rotate=\theangle] (0,0) -- (1.5,0);
            
        \draw[->] (0.5,0)  arc [start angle=0, delta angle=\theangle, radius=0.5cm];
    %    \draw (0.75,0.25) node[anchor= south west]{$\;\varphi = \omega t + \varphi_0$};
            
        \draw[orange] (2,2) node {\theangle$^\circ$};
        \fill[black] (0,0) circle (1mm);
            
    %    \draw (1.5,-2.5) circle (0.5mm);
        \draw[->] (3,-2) -- +(0,4) node[left]{$y$};
        \draw[->] (3,0) -- +(6.5,0) node[below]{$t$};
        \draw[blue,xshift=3cm, x=1.5cm, y=1.5cm, name path=sine curve] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
        \path[name path=proj line] (\theangle\xperdeg, -2) ++(3,0) -- +(0,4);
        \draw[name intersections={of=sine curve and proj line}]
          (3,0) +(\theangle\xperdeg,0) -- (intersection-1) -- (\theangle:1.5cm) 
          (intersection-1) circle[radius=0.5mm];
    %    \draw[rotate=-90,xshift=2.5cm,yshift=1.5cm] (0,0) cos++ (1.5,-1.5) sin++ (1.5,-1.5) cos++(1.5,1.5) sin++(1.5,1.5);
                
      \end{tikzpicture}
            
    \end{document}
    0 und 360 funktioniert hier für den angle-Zähler nicht, was evtl daran liegt, daß die Sinuskurve nur berührt aber nicht geschnitten wird. Teste es erstmal mit Werten im Bereich 1..359.

    VG
    Rainer
    Rainer
    There's nothing a good whack with a hammer won't fix!

  3. #3
    Registrierter Benutzer Avatar von rais
    Registriert seit
    18.07.2005
    Beiträge
    5.862
    Wobei, wenn man etwas schummelt, funktioniert das auch mit 0° und 360°:
    Code:
    xshift=2.9999cm, x=1.50005cm
    bei den Optionen für die Sinuskurve sorgt dafür, daß diese 1 µm vorher anfängt und 1 µm später aufhört, etwaige Rundungsfehler außer Acht gelassen. Selbst das Zehnfache davon wäre nicht wahrnehmbar.

    Der Kosinus lässt sich dazu analog abbilden:
    Code:
    \documentclass[tikz]{standalone}
    
    \usetikzlibrary{intersections}
    
    \newcounter{angle}
    \setcounter{angle}{60}
    \newlength\xperdeg
    \setlength\xperdeg{0.166667mm}% Breite der Sinuskurve / Vollkreis (6cm/360°)
    
    \begin{document}
      \begin{tikzpicture}
        \draw[black!20] (0,1.5) -- +(4.5,0) %Projektierungslinien
          (0,-1.5) -- +(7.5,0)
          (2,0) -- (3,0)
          (-1.5,0) -- +(0,-6)
          (1.5,0) -- +(0,-9)
          (0,-2) -- (0,-3);
        \draw[thick,->] (-2,0)--(2,0) node[below] {$x$}; 
        \draw[thick,->] (0,-2)--(0,2) node[left] {$y$};
        \draw[red,thick] (0,0) circle (1.5cm);
        \draw (1.6,0) node[red, below]{1};
        \draw (0,1.65) node[red,left]{1};
    %
        \draw[ultra thick,cyan] (0,0) -- (0,0 |- \theangle:1.5cm); % Siehe `texdoc pgfmanual', Abschnitt ``Intersections of Perpendicular Lines''
        \draw[ultra thick,orange] (0,0) -- (\theangle:1.5cm |- 0,0);
    %
        \draw[densely dotted,orange] (\theangle:1.5cm) -- (\theangle:1.5cm |- 0,0); 
        \draw[densely dotted,cyan] (\theangle:1.5cm) -- (0,0 |- \theangle:1.5cm); 
        \draw[ultra thick,red,->,rotate=\theangle] (0,0) -- (1.5,0);
            
        \draw[->] (0.5,0)  arc [start angle=0, delta angle=\theangle, radius=0.5cm];
    %    \draw (0.75,0.25) node[anchor= south west]{$\;\varphi = \omega t + \varphi_0$};
            
        \draw[orange] (2,2) node {\theangle$^\circ$};
        \fill[black] (0,0) circle (1mm);
            
        \draw[->] (3,-2) -- +(0,4) node[left]{$y$};% für die Sinuskurve
        \draw[->] (3,0) -- +(6.5,0) node[below]{$t$};
        \draw[->] (-2,-3) -- +(4,0) node[above]{$y$};% für die Kosinuskurve
        \draw[->] (0,-3) -- +(0, -6.5) node[left]{$t$};
        \draw[blue,xshift=2.9999cm, x=1.50005cm, y=1.5cm, name path=sine curve] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
        \draw[red, yshift=-2.9999cm, rotate=-90, x=1.50005cm, y=1.5cm, name path=cosine curve] (0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);
        \path[name path=proj sline] (\theangle\xperdeg, -2) ++(3,0) -- +(0,4);
        \path[name path=proj cline] (-2, -\theangle\xperdeg) ++(0,-3) -- +(4,0);
        \draw[name intersections={of=sine curve and proj sline}, cyan]
          (3,0) +(\theangle\xperdeg,0) -- (intersection-1) -- (\theangle:1.5cm);
        \draw (intersection-1) circle[radius=0.5mm];
        \draw[name intersections={of=cosine curve and proj cline}, orange]
          (0,-3) +(0,-\theangle\xperdeg) -- (intersection-1) -- (\theangle:1.5cm);
        \draw (intersection-1) circle[radius=0.5mm];
      \end{tikzpicture}
            
    \end{document}
    Frohe Ostern
    Rainer
    There's nothing a good whack with a hammer won't fix!

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •