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?
[Tex/LaTex] Projectile Motion Diagram using PGFplots/tikz
pgfplotstikz-pgf
Related Solutions
You might be interessted in PGFplots (see: pgfplots.sf.net)
\begin{tikzpicture}
\begin{axis}[
3d box=background,
% pretty printing, but irrelevant:
title={3d box=background},
samples=5,
domain=-4:4,
xtick=-4:4,
ytick=-4:4,
]
\addplot3[surf] {1*x*y};
\end{axis}
\end{tikzpicture}
In the official documentation of PGFplots, therer's are some options mentioned about parametric ploting:
- /pgfplots/parametric
- /pgfplots/parametric/var 1d
- /pgfplots/parametric/var 2d
With PGFplots you can use GNUplot aswell:
\begin{tikzpicture}
\begin{axis}
\addplot3 gnuplot[raw gnuplot] {set parametric;splot[t=0:6*pi] cos(t),sin(t),t/2*pi};
\end{axis}
\end{tikzpicture}
The answer is surprisingly simple. It transpires that the \foreach
command can't come at arbitrary places in a path command. My guess, based on experiment, would be that it can only come when TikZ is looking for the next type of path, namely just after a coordinate. Once TikZ knows the type of path, it goes into a different mode where it looks just for those things it knows can be part of that path.
As a simpler example, try:
\draw (0,0) -- \foreach \a in {0,1,...,10} {(\a,0) -- (\a,1) -- } (11,0);
Here, TikZ is looking for a coordinate when it encounters the \foreach
, so it complains. The simplest solution is to switch things around a little to ensure that the \foreach
comes when TikZ is expecting it. In the baby example, this would be:
\draw (0,0) \foreach \a in {0,1,...,10} { -- (\a,0) -- (\a,1) } -- (11,0);
To a human, these are the same, but the second compiles (and gives a nice sawtooth wave) because TikZ encounters the \foreach
when it is able to cope with it.
In your example, you would have:
\pgfmathsetmacro{\in}{#1}
\pgfmathsetmacro{\out}{#2}
\pgfmathsetmacro{\intop}{2*\in - 4}
\pgfmathsetmacro{\intopp}{2*\in - 2}
% Connected piece
\draw
(0,0) \foreach \a in {0,2,...,\intop}{
.. controls (-0.25,\a) and (-0.25,\a+1) .. (0,\a+1) ..
controls (0.5,\a+1) and (0.5,\a+2) .. (0,\a+2)
} .. controls (-0.25,\intopp) and (-0.25,\intopp+1) ..
(0,\intopp+1);
So I've shifted the first ..
inside the \foreach
, and the last ..
that was inside the loop outside again. This now works.
This answer was sponsored by the Answers to Packages team, suppliers of cobordisms for quality TQFTs.
Best Answer
This proposal uses
animate
in thebeamer
class, viatikz
, 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 usesg=2
instead ofg=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 thebeamer
class toartice
class and remove the\begin/\end{frame}
andnavigation
. Of course, for the vectors to show up, aforeach
loop with conditional check is added in this new update.Code
Update: (2014/12/8) --- Thanks for Ellett's insight that improves the coding.
Code