为什么使用 \draw 和计算坐标不符合抛射运动图应有的样子?有没有关于使用坐标中的公式的代码的建议?
\begin{tikzpicture}[scale=0.6, transform shape] %projectile motion
\begin{axis}[
width=12cm, %set bigger width
height=6cm,
xmin=0,xmax=10,
ymin=0,ymax=10,
xlabel=$x$,
ylabel=$y$,
axis x line = bottom,
axis y line = left,
axis line style={->},
%axis on top,
ticks = none
]
%variable definitions
\def\g{-9.8} %gravity
\def\v{10} %velocity
\def\ang{51} %angle
\pgfmathsetmacro{\t}{0}
%flight path
\addplot[
dashed,
thick,
domain=0:10,
samples=100,]
{{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}}
node[above,pos=0.5]{$V_y=0$};
%vector at start
\coordinate (A) at ({\v*cos(\ang)*\t},{\v*\t*sin(\ang)+0.5*\g*(\t^2)});
\coordinate (B) at ({\v*cos(\ang)*\t+\v*cos(\ang)},{\v*\t*sin(\ang)+0.5*\g*\t^2+\v*sin(\ang)+\g*\t});
\coordinate (C) at ({\v*cos(\ang)*\t+\v*cos(\ang)}, {\v*\t*sin(\ang)+0.5*\g*\t^2});
\coordinate (D) at ({\v*cos(\ang)*\t},{\v*\t*sin(\ang) + 0.5*\g*(\t^2) + \v*sin(\ang) + \g*\t)});
\draw[very thick,->](A)--(B);
\draw[very thick,->](A)--(C);
\draw[very thick,->](A)--(D);
%vector at end
%\pgfmathsetmacro{\a}{1.5}
\pgfmathsetmacro{\a}{{-1*(2/\g)*\v*sin(\ang)}}
\coordinate (E) at ({\v*cos(\ang)*\a},{\v*\a*sin(\ang)+0.5*\g*(\a^2)});
\coordinate (F) at ({\v*cos(\ang)*\a+\v*cos(\ang)},{\v*\a*sin(\ang)+0.5*\g*\a^2+\v*sin(\ang)+\g*\a});
\coordinate (G) at ({\v*cos(\ang)*\a+\v*cos(\ang)}, {\v*\a*sin(\ang)+0.5*\g*\a^2});
\coordinate (H) at ({\v*cos(\ang)*\a},{\v*\a*sin(\ang) + 0.5*\g*(\a^2) + \v*sin(\ang) + \g*\a)});
\draw[very thick,->](E)--(F);
\draw[very thick,->](E)--(G);
\draw[very thick,->](E)--(H);
%vector 1/2 up
%\pgfmathsetmacro{\b}{0.3}
\pgfmathsetmacro{\b}{{(-1*(2/\g)*\v*sin(\ang))/4}}
\coordinate (H) at ({\v*cos(\ang)*\b},{\v*\b*sin(\ang)+0.5*\g*(\b^2)});
\coordinate (I) at ({\v*cos(\ang)*\b+\v*cos(\ang)},{\v*\b*sin(\ang)+0.5*\g*\b^2+\v*sin(\ang)+\g*\b});
\coordinate (J) at ({\v*cos(\ang)*\b+\v*cos(\ang)}, {\v*\b*sin(\ang)+0.5*\g*\b^2});
\coordinate (K) at ({\v*cos(\ang)*\b},{\v*\b*sin(\ang) + 0.5*\g*(\b^2) + \v*sin(\ang) + \g*\b)});
\draw[very thick,->](H)--(I);
\draw[very thick,->](H)--(J);
\draw[very thick,->](H)--(K);
%vector halfway
%\pgfmathsetmacro{\c}{0.8}
\pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}}
\coordinate (L) at ({\v*cos(\ang)*\c},{\v*\c*sin(\ang)+0.5*\g*(\c^2)});
\coordinate (M) at ({\v*cos(\ang)*\c+\v*cos(\ang)},{\v*\c*sin(\ang)+0.5*\g*\c^2+\v*sin(\ang)+\g*\c});
\coordinate (N) at ({\v*cos(\ang)*\c+\v*cos(\ang)}, {\v*\c*sin(\ang)+0.5*\g*\c^2});
\coordinate (O) at ({\v*cos(\ang)*\c},{\v*\c*sin(\ang) + 0.5*\g*(\c^2) + \v*sin(\ang) + \g*\c)});
\draw[very thick,->](L)--(M);
\draw[very thick,->](L)--(N);
\draw[very thick,->](L)--(O);
%vector 1/2 down
%\pgfmathsetmacro{\d}{1.2}
\pgfmathsetmacro{\d}{{(-1*(2/\g)*\v*sin(\ang))*0.75}}
\coordinate (P) at ({\v*cos(\ang)*\d},{\v*\d*sin(\ang)+0.5*\g*(\d^2)});
\coordinate (Q) at ({\v*cos(\ang)*\d+\v*cos(\ang)},{\v*\d*sin(\ang)+0.5*\g*\d^2+\v*sin(\ang)+\g*\d});
\coordinate (R) at ({\v*cos(\ang)*\d+\v*cos(\ang)}, {\v*\d*sin(\ang)+0.5*\g*\d^2});
\coordinate (S) at ({\v*cos(\ang)*\d},{\v*\d*sin(\ang) + 0.5*\g*(\d^2) + \v*sin(\ang) + \g*\d)});
\draw[very thick,->](P)--(Q);
\draw[very thick,->](P)--(R);
\draw[very thick,->](P)--(S);
\end{axis}
答案1
这是调查 OP 的代码后提出的解决方案。
axis cs:x,y
pgfplots
当使用 tikz 命令时应该使用语法。- 解决方案是添加一个缩放因子
\s
并将其设置为 0.2,以便获得更好的呈现效果。设置\s
为 1 将是 OP 的原始值。 - 对于矢量绘图,只需要两个点,因为可以使用坐标技能绘制
v_x
和。v_y
orthogonal
代码
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.6, transform shape] %projectile motion
\begin{axis}[
width=12cm, %set bigger width
height=6cm,
xmin=0,xmax=10,
ymin=0,ymax=10,
xlabel=$x$,
ylabel=$y$,
axis x line = bottom,
axis y line = left,
axis line style={->},
%axis on top,
ticks = none,clip=false,
]
%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,
thick,
domain=0:10,
samples=100,]
{{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}}
node[above,pos=0.5]{$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)});
%\node (C) at (axis cs: {\v*cos(\ang)*\t+\v*cos(\ang)}, {\v*\t*sin(\ang)+0.5*\g*\t^2}){c};
%\node (D) at (axis cs: {\v*cos(\ang)*\t}, {\v*\t*sin(\ang) + 0.5*\g*(\t^2) + \v*sin(\ang) + \g*\t}){d};
\draw[very thick,->](A)--(B);
\draw[very thick,->](A)--(B|-A);
\draw[very thick,->](A)--(B-|A);
%vector at end
\pgfmathsetmacro{\a}{1.5}
\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)});
%\coordinate (G) at (axis cs:{\v*cos(\ang)*\a+\v*cos(\ang))}, {\v*\a*sin(\ang)+0.5*\g*\a^2)});
%\coordinate (H) at (axis cs:{\v*cos(\ang)*\a}, {(\v*\a*sin(\ang) + 0.5*\g*(\a^2) + \v*sin(\ang) + \g*\a))});
\draw[very thick,->](E)--(F);
\draw[very thick,->](E)--(F |- E);
\draw[very thick,->](E)--(F-| E);
%
%vector 1/2 up
%\pgfmathsetmacro{\b}{0.3}
\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)});
%\coordinate (J) at (axis cs:{\v*cos(\ang)*\b+\v*cos(\ang)}, {\v*\b*sin(\ang)+0.5*\g*\b^2});
%\coordinate (K) at (axis cs:{\v*cos(\ang)*\b},{\v*\b*sin(\ang) + 0.5*\g*(\b^2) + \v*sin(\ang) + \g*\b)});
\draw[very thick,->](H)--(I);
\draw[very thick,->](H)--(I-|H);
\draw[very thick,->](H)--(I|-H);
%
%vector halfway
%\pgfmathsetmacro{\c}{0.8}
\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)});
%\coordinate (N) at (axis cs:{\v*cos(\ang)*\c+\v*cos(\ang)}, {\v*\c*sin(\ang)+0.5*\g*\c^2});
%\coordinate (O) at (axis cs:{\v*cos(\ang)*\c},{\v*\c*sin(\ang) + 0.5*\g*(\c^2) + \v*sin(\ang) + \g*\c)});
\draw[very thick,->](L)--(M);
\draw[very thick,->](L)--(M|-L);
\draw[very thick,->](L)--(M-|L);
%vector 1/2 down
%\pgfmathsetmacro{\d}{1.2}
\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)});
%\coordinate (R) at (axis cs:{\v*cos(\ang)*\d+\v*cos(\ang)}, {\v*\d*sin(\ang)+0.5*\g*\d^2});
%\coordinate (S) at (axis cs:{\v*cos(\ang)*\d},{\v*\d*sin(\ang) + 0.5*\g*(\d^2) + \v*sin(\ang) + \g*\d)});
\draw[very thick,->](P)--(Q);
\draw[very thick,->](P)--(Q|-P);
\draw[very thick,->](P)--(Q-|P);
\end{axis}
\end{tikzpicture}
\end{document}