[Tex/LaTex] Projectile Motion Diagram using PGFplots/tikz

pgfplotstikz-pgf

I'm making an equation sheet for my physics class (using LaTeX), and we're doing a section on projectile motion/vectors. Are there any suggestions for drawing diagrams using either plain Tikz or PGFplots like the ones I find in my textbook?

half motion diagram

full motion diagram

Best Answer

This proposal uses animate in the beamer class, via tikz, to simulate projectile motions and one can see the vectors at any instant by clicking the > arrow at the bottom while triangle is for a continuous trajectory. The simulation uses g=2 instead of g=9.8 so that more points can be obtained.

Update (2014/12/9) The OP needs the graph in article class and the 5 vectors. So this is an update. Basically, simply change the beamer class to artice class and remove the \begin/\end{frame} and navigation. Of course, for the vectors to show up, a foreach loop with conditional check is added in this new update.

enter image description here

Code

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{animate}
\usepackage{ifthen}
%\setbeamertemplate{navigation symbols}{}
\begin{document}
%\begin{frame}
\def\rg{2}
\begin{animateinline}[poster=first,controls]{8}%
\multiframe{37}{rt=0+.1,icount=1+1,rvo=5+0.0,rtheta=45+.0}
{% rt=time, rvo=initial v, g=2, rtheta=inital angle
\begin{tikzpicture}[scale=.75]
\clip (-1,-2) rectangle (15,10); % For body projected upward with angle rtheta=45
%\clip (-1,-8) rectangle (15,1);   % For body projected horizontally, rtheta=0
\draw[red] (0,0)--(13,0);         % ground horizontal line
\coordinate (A\icount) at ({\rvo*cos(\rtheta)*(\rt)},{\rvo*sin(\rtheta)*(\rt)-0.5*\rg*(\rt)*(\rt)}) {};              % (x,y) position,
\path (A\icount) -- + ({0.5*\rvo*cos(\rtheta)},{0.5*(\rvo*sin(\rtheta)-\rg*(\rt))}) coordinate (B\icount){};  % (V_x,V_y) position , scaled by 0.5
\draw[thick,green,->] (A\icount.center) -- (B\icount-|A\icount);
\draw[thick,green,->] (A\icount.center) -- (B\icount|-A\icount);
\draw[thick,green,->] (A\icount.center) -- (B\icount);
\ifthenelse{\icount > 1}
{\draw ({\rvo*cos(\rtheta)*(\rt)},0) node[below]{\tiny S=\rvo*cos(\rtheta)*(\rt)};                               % x displacement
\foreach \x in {.0,.1,...,\rt}
\filldraw [blue]
({\rvo*cos(\rtheta)*(\x)}, {\rvo*sin(\rtheta)*(\x)-0.5*\rg*(\x)*(\x)}) circle (1pt);
\foreach \i in {1,9,19,28,36}{ % adjust this frame number to show the vectors
\ifnum \icount >\i
\draw[thick,blue,->] (A\i.center) -- (B\i-|A\i);
\draw[thick,blue,->] (A\i.center) -- (B\i|-A\i);
\draw[thick,blue,->] (A\i.center) -- (B\i);
\ifnum \icount>19
\node [red,above=0.2cm] at (A19){$v_y=0$};
\fi
\fi
}
}
{}
\filldraw [red] 
({\rvo*cos(\rtheta)*(\rt)}, {\rvo*sin(\rtheta)*(\rt)-0.5*\rg*(\rt)*(\rt)}) circle (2pt);
\end{tikzpicture}
   }
\end{animateinline}
%\end{frame}
\end{document}

enter image description here enter image description here enter image description here

Update: (2014/12/8) --- Thanks for Ellett's insight that improves the coding.

Code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{animate}
\usepackage{ifthen}
\setbeamertemplate{navigation symbols}{}
\begin{document}
\begin{frame}
\def\rg{2}
\begin{animateinline}[poster=first,controls]{8}%
\multiframe{40}{rt=0+.1,icount=1+1,rvo=5+0.0,rtheta=45+.0}
{% rt=time, rvo=initial v, g=2, rtheta=inital angle
\begin{tikzpicture}[scale=.75]
\clip (-1,-2) rectangle (15,10); % For body projected upward with angle rtheta=45
%\clip (-1,-8) rectangle (15,1);   % For body projected horizontally, rtheta=0
\draw[red] (0,0)--(13,0);         % ground horizontal line
\node (A\icount) at ({\rvo*cos(\rtheta)*(\rt)},{\rvo*sin(\rtheta)*(\rt)-0.5*\rg*(\rt)*(\rt)}) {};     % (x,y) position,
\path (A\icount) -- + ({0.5*\rvo*cos(\rtheta)},{0.5*(\rvo*sin(\rtheta)-\rg*(\rt))}) node (B\icount){};% (V_x,V_y) position,scaled by 0.5
\draw[thick,green,->] (A\icount.center) -- (B\icount-|A\icount);
\draw[thick,green,->] (A\icount.center) -- (B\icount|-A\icount);
\draw[thick,green,->] (A\icount.center) -- (B\icount);    
\ifthenelse{\icount > 1}
{\draw ({\rvo*cos(\rtheta)*(\rt)},0) node[below]
{\tiny S=\rvo*cos(\rtheta)*(\rt)};                                % x displacement
\foreach \x in {.0,.1,...,\rt}
\filldraw [blue]
({\rvo*cos(\rtheta)*(\x)}, {\rvo*sin(\rtheta)*(\x)-0.5*\rg*(\x)*(\x)}) circle (1pt);}
{}
\filldraw [red] 
({\rvo*cos(\rtheta)*(\rt)}, {\rvo*sin(\rtheta)*(\rt)-0.5*\rg*(\rt)*(\rt)}) circle (2pt);

\end{tikzpicture}
   }
\end{animateinline}
\end{frame}
\end{document}
Related Question