
Wie kann ich eine Parabelgrafik zeichnen $f(x)=x^2$
und eine vertikale Animation davon erstellen, sodass sich die Grafik nach rechts und links bewegt? Dies ist mein minimales funktionierendes Beispiel.
\documentclass{standalone}
\usepackage{mathtools} %includes amsmath
\usepackage{mathabx}
\usepackage{tikz}
\usetikzlibrary{patterns,calc,arrows}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}[>=triangle 45, cap=round]
\draw[->] (-4.0,0) -- (4.0,0);
\node[below] at (4.0, 0.0) {\textit{x}};
\draw[->] (0,-4.0) -- (0,4.0);
\node[left] at (0.0,4.0) {\textit{f(x)}};
\draw[blue, line width=1.75pt, domain=-2.00 : 2.00, samples=1500] plot[smooth](\x, {\x*\x });
\end{tikzpicture}
\end{document}
Wie kann ich diese Parabel langsam drei Einheiten nach rechts verschieben, die Farbe ändern und schreiben $f(x-3)$
?
Antwort1
Mit dem animate
Paket können Sie beispielsweise Folgendes tun:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\begin{animateinline}[controls, palindrome]{15}
\multiframe{33}{rt=-4+0.25}{
\begin{tikzpicture}
\\clip (-5.5,-1.5) rectangle (5.5,9.5);
\draw[->] (-5,0) -- (5,0) node[above] {$x$};
\draw[->] (0,-1) -- (0,9) node[above] {$y$};
\path (0,0) node[below left] {$0$};
\begin{scope}[shift={(\rt,0)}]
\draw (-4,8) parabola bend (0,0) (4,8);
\end{scope}
\pgfmathsetmacro{\y}{abs(\rt^2)/2}
\node[fill=red, circle, inner sep=2pt] at (0,\y) {};
\end{tikzpicture}
}
\end{animateinline}
\end{document}
Angewandt auf dein MWE könnte dein Code dann so aussehen (da ich nicht wusste, auf welche Farbe du wechseln möchtest, habe ich einfach Rot gewählt):
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{animate}
\begin{document}
\begin{animateinline}[controls, palindrome]{4}
\multiframe{4}{rt=0+1}{
\begin{tikzpicture}[>=triangle 45, cap=round]
\clip (-4.5,-4.5) rectangle (4.5,4.5);
\draw[->] (-4,0) -- (4,0);
\node[below] at (4,0) {$x$};
\draw[->] (0,-4) -- (0,4);
\ifdim\rt pt=0pt\relax
\node[left] at (0,4) {$f(x)$};
\else
\node[left] at (0,4) {$f(x - \pgfmathprintnumber[precision=3]{\rt})$};
\fi
\pgfmathtruncatemacro{\colorgrad}{\rt/(4-1)*100}
\draw[red!\colorgrad!blue, line width=1.75pt, domain=-2.00 : 2.00, samples=101] plot[smooth] ({\x+\rt}, {\x*\x});
\end{tikzpicture}
}
\end{animateinline}
\end{document}
Man könnte natürlich auch noch weitere Schritte hinzufügen, aber dann müsste man sich überlegen, was man als Beschriftung für diejAchse. (Der obige Code ist etwas „gehärtet“ und akzeptiert jetzt auch Gleitkommazahlen, sodass Sie mit verschiedenen Einstellungen herumspielen können.)