使用 PGFplots/tikz 的抛射运动图?

使用 PGFplots/tikz 的抛射运动图?

我正在为我的物理课制作一个方程式表(使用 LaTeX),我们正在做关于抛射运动/矢量的部分。有没有建议使用普通的 Tikz 或 PGFplots 绘制图表,就像我在课本上找到的那样?

半运动图

全动态图

答案1

本提案animatebeamer课程中使用 来模拟抛射运动,点击底部的箭头tikz即可查看任意时刻的矢量,三角形表示连续轨迹。模拟使用而不是,以便获得更多点。>g=2g=9.8

更新(2014/12/9) 楼主需要article类中的图表和 5 个向量。所以这是一个更新。基本上,只需将beamer类更改为artice类并删除\begin/\end{frame}and navigation。当然,为了让向量显示出来,foreach在这个新的更新中添加了一个带有条件检查的循环。

在此处输入图片描述

代码

\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}

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

更新:(2014/12/8) --- 感谢 Ellett 的见解,改进了编码。

代码

\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}

答案2

(原作者在此)经过一番努力(以及这里的帮助!),我制作了一个图表,希望其他人会觉得有用。软件包pgfplotstikz被使用,而 tikz 库positioningcalcplotmarks被使用。

所有内容都是根据 下的变量列表计算得出的%variable definitions。我无法找出\t在每组坐标计算/绘图之前重新定义的方法,因此每个矢量点都有不同的(小写)时间变量。

第一个向量处的角度标签由 2 个相同的圆节点组成;一个未剪切,因此 theta 节点可以参考它定位,另一个已剪切,以便实际绘制圆/弧。您必须定义/计算自己的圆大小和角度,以使其效果最佳。

让最后一个向量之后的结尾不等于,xmax=11.5这样图形将占用更多的空间/并且更容易看到,以便于演示目的。x axisymaxxmax

如果您对优化/清理代码或找到更简洁的方式来标记起始矢量角度有任何建议,请告诉我!

抛射体运动图

\begin{tikzpicture}[scale=1, transform shape]  %projectile motion
\begin{axis}[
width=10cm, %set bigger width
height=5cm,
xmin=0,xmax=11.5,
ymin=0,ymax=4,
xlabel=$x$,
ylabel=$y$,
axis x line = bottom,
axis y line = left,
axis line style={->},
%axis on top,
ticks = none,clip=false,
]

\tikzset{every mark/.append style={fill=white}}

%variable definitions
\def\g{-9.8} %gravity
\def\v{10} %velocity
\def\ang{51} %angle
\def\s{0.2}
\pgfmathsetmacro{\t}{0}
%flight path
\addplot[
dashed,
domain=0:10,
samples=100,]
{{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}}
node[midway,above]{$V_y=0$};

%vector at start
\coordinate (A) at (axis cs: {\v*cos(\ang)*\t}, {\v*\t*sin(\ang)+0.5*\g*(\t^2)});
\coordinate (B) at (axis cs: {\v*cos(\ang)*\t+\s*\v*cos(\ang)}, {\v*\t*sin(\ang)+0.5*\g*\t^2+\s*(\v*sin(\ang)+\g*\t)});
\draw[very thick,->](A)--(B)
node[midway,sloped,above]{$V$};
\draw[densely dashed,very thick,->](A)--(B|-A)
node[midway,below]{$V_x$};
\draw[densely dashed,very thick,->](A)--(B-|A)
node[midway,left]{$V_y$};

\path plot[mark=*] coordinates {(A)};

%dashed box around start vector
\draw[dashed](B-|A)--(B);
\draw[dashed](B|-A)--(B);

%vector at end
\pgfmathsetmacro{\a}{{-1*(2/\g)*\v*sin(\ang)}}
\coordinate (E) at (axis cs:{\v*cos(\ang)*\a},{\v*\a*sin(\ang)+0.5*\g*(\a^2)}){};
\coordinate (F) at (axis cs:{\v*cos(\ang)*\a+\s*\v*cos(\ang))}, {\v*\a*sin(\ang)+0.5*\g*\a^2+\s*(\v*sin(\ang)+\g*\a)});
\draw[very thick,->](E)--(F)
node[midway,sloped,above]{$V$};
\draw[densely dashed,very thick,->](E)--(F |- E)
node[midway,above]{$V_x$};
\draw[densely dashed,very thick,->](E)--(F-| E)
node[midway,left]{$V_y$};

\path plot[mark=*] coordinates {(E)};

%vector 1/2 up
\pgfmathsetmacro{\b}{{(-1*(2/\g)*\v*sin(\ang))/4}}
\coordinate (H) at (axis cs:{\v*cos(\ang)*\b},{\v*\b*sin(\ang)+0.5*\g*(\b^2)});
\coordinate (I) at (axis cs: {\v*cos(\ang)*\b+\s*\v*cos(\ang)},{\v*\b*sin(\ang)+0.5*\g*\b^2+\s*(\v*sin(\ang)+\g*\b)});
\draw[very thick,->](H)--(I)
node[midway,sloped,above]{$V$};
\draw[densely dashed,very thick,->](H)--(I-|H)
node[midway,left]{$V_x$};
\draw[densely dashed,very thick,->](H)--(I|-H)
node[midway,below]{$V_y$};

\path plot[mark=*] coordinates {(H)};

%vector halfway
\pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}}
\coordinate (L) at (axis cs:{\v*cos(\ang)*\c},{\v*\c*sin(\ang)+0.5*\g*(\c^2)});
\coordinate (M) at (axis cs:{\v*cos(\ang)*\c+\s*\v*cos(\ang))},{\v*\c*sin(\ang)+0.5*\g*\c^2+\s*(\v*sin(\ang)+\g*\c)});
\draw[very thick,->](L)--(M)
node[midway,sloped,below]{$V$};


%T2 line; halfway up flight path
\draw[loosely dashed] (L) -- (axis cs:{\v*cos(\ang)*\c},0)
node[midway,right] {$\frac{t_\text{total}}{2}$};


\path plot[mark=*] coordinates {(L)};

%vector 1/2 down
\pgfmathsetmacro{\d}{{(-1*(2/\g)*\v*sin(\ang))*0.75}}
\coordinate (P) at (axis cs:{\v*cos(\ang)*\d},{\v*\d*sin(\ang)+0.5*\g*(\d^2)});
\coordinate (Q) at (axis cs:{(\v*cos(\ang)*\d+\s*\v*cos(\ang))},{\v*\d*sin(\ang)+0.5*\g*\d^2+\s*(\v*sin(\ang)+\g*\d)});
\draw[very thick,->](P)--(Q)
node[midway,sloped,below]{$V$};
\draw[densely dashed,very thick,->](P)--(Q|-P)
node[midway,above]{$V_x$};
\draw[densely dashed,very thick,->](P)--(Q-|P)
node[midway,left]{$V_y$};

\path plot[mark=*] coordinates {(P)};

%start vector angle label
\node[circle,minimum size=25pt] at (A) (circ) {};
\node[right] at (circ.30) {$\theta$};
\path[clip] (A) -- (B) -- (B|-A) -- cycle;
\node[circle,draw,minimum size=25pt] at (A) (circ) {};
\end{axis}
\end{tikzpicture}

对于水平投影:

\begin{tikzpicture}[scale=2, transform shape]  %horizontal projection
%variable definitions
\def\g{-9.8} %gravity
\def\v{10} %velocity
\def\ang{51} %angle
\def\s{0.1}
\pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}}

\begin{axis}[
width=.45\linewidth, %set bigger width
height=2.2in,
xmin={{\v*cos(\ang)*\c}},xmax=11.5,
ymin=0,ymax={\v*\c*sin(\ang)+0.5*\g*(\c^2)},,
xlabel=$x$,
ylabel=$y$,
axis x line = bottom,
axis y line = left,
y axis line style={-},
ticks = none,clip=false,
]

\tikzset{every mark/.append style={fill=white}}

%flight path
\addplot[
dashed,
domain={\v*cos(\ang)*\c}:10,
samples=100,]
{{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}};

%vector at end
\pgfmathsetmacro{\a}{{-1*(2/\g)*\v*sin(\ang)}}
\coordinate (E) at (axis cs:{\v*cos(\ang)*\a},{\v*\a*sin(\ang)+0.5*\g*(\a^2)}){};
\coordinate (F) at (axis cs:{\v*cos(\ang)*\a+\s*\v*cos(\ang))}, {\v*\a*sin(\ang)+0.5*\g*\a^2+\s*(\v*sin(\ang)+\g*\a)});
\draw[very thick,->](E)--(F)
node[right, at end,font=\tiny]{$\vec{V}$};
\draw[densely dashed,very thick,->](E)--(F |- E)
node[midway,above,font=\tiny]{$\vec{V}_x$};
\draw[densely dashed,very thick,->](E)--(F-| E)
node[midway,left,font=\tiny]{$\vec{V}_y$};

\path plot[mark=*] coordinates {(E)};

%vector at start
\pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}}
\coordinate (L) at (axis cs:{\v*cos(\ang)*\c},{\v*\c*sin(\ang)+0.5*\g*(\c^2)});
\coordinate (M) at (axis cs:{\v*cos(\ang)*\c+\s*\v*cos(\ang))},{\v*\c*sin(\ang)+0.5*\g*\c^2+\s*(\v*sin(\ang)+\g*\c)});
\draw[very thick,->](L)--(M)
node[midway,sloped,above,font=\tiny]{$\vec{V}$};

\path plot[mark=*] coordinates {(L)};

%vector 1/2 down
\pgfmathsetmacro{\d}{{(-1*(2/\g)*\v*sin(\ang))*0.75}}
\coordinate (P) at (axis cs:{\v*cos(\ang)*\d},{\v*\d*sin(\ang)+0.5*\g*(\d^2)});
\coordinate (Q) at (axis cs:{(\v*cos(\ang)*\d+\s*\v*cos(\ang))},{\v*\d*sin(\ang)+0.5*\g*\d^2+\s*(\v*sin(\ang)+\g*\d)});
\draw[very thick,->](P)--(Q)
node[right, at end,font=\tiny]{$\vec{V}$};
\draw[densely dashed,very thick,->](P)--(Q|-P)
node[midway,above,font=\tiny]{$\vec{V}_x$};
\draw[densely dashed,very thick,->](P)--(Q-|P)
node[midway,left,font=\tiny]{$\vec{V}_y$};

\path plot[mark=*] coordinates {(P)};

%vector 3/4 down
\pgfmathsetmacro{\f}{{(-1*(2/\g)*\v*sin(\ang))*0.6}}
\coordinate (R) at (axis cs:{\v*cos(\ang)*\f},{\v*\f*sin(\ang)+0.5*\g*(\f^2)});
\coordinate (S) at (axis cs:{(\v*cos(\ang)*\f+\s*\v*cos(\ang))},{\v*\f*sin(\ang)+0.5*\g*\f^2+\s*(\v*sin(\ang)+\g*\f)});
\draw[very thick,->](R)--(S)
node[right, at end,font=\tiny]{$\vec{V}$};
\draw[densely dashed,very thick,->](R)--(S|-R)
node[midway,above,font=\tiny]{$\vec{V}_x$};
\draw[densely dashed,very thick,->](R)--(S-|R)
node[at end,below,font=\tiny]{$\vec{V}_y$};

\path plot[mark=*] coordinates {(R)};

%vector 1/4 down
\pgfmathsetmacro{\e}{{(-1*(2/\g)*\v*sin(\ang))*0.875}}
\coordinate (T) at (axis cs:{\v*cos(\ang)*\e},{\v*\e*sin(\ang)+0.5*\g*(\e^2)});
\coordinate (U) at (axis cs:{(\v*cos(\ang)*\e+\s*\v*cos(\ang))},{\v*\e*sin(\ang)+0.5*\g*\e^2+\s*(\v*sin(\ang)+\g*\e)});
\draw[very thick,->](T)--(U)
node[right, at end,font=\tiny]{$\vec{V}$};
\draw[densely dashed,very thick,->](T)--(U|-T)
node[midway,above,font=\tiny]{$\vec{V}_x$};
\draw[densely dashed,very thick,->](T)--(U-|T)
node[midway,left,font=\tiny]{$\vec{V}_y$};

\path plot[mark=*] coordinates {(T)};

\end{axis}
\end{tikzpicture}

水平投影

基本上是相同的代码,只是您将最大 y 值定义为中点高度的方程。y axis line style={-}添加 ,这样就不存在 y 轴箭头;否则它会与圆形标记冲突。 箭头用 更改\tikzset{>=stealth}

相关内容