写了一个平抛和一个斜抛
斜抛是可以自定义参数的
平抛是死的
怎么把两个图放在一起展示
斜抛:
%斜抛运动
clear; %清除所有变量
clc; %清屏
global location V0 alpha g; %定义全局变量
options={'初始位置(坐标)','初始速度V0' ,'抛射角度','重力加速度g',};
topic='seting';
lines=1; %输入框行数
def={'[0,0]','20','45','9.8'}; %初始值
h=inputdlg(options,topic,lines,def);%构造输入对话框
location=eval(h{1});
V0=eval(h{2});
alpha=eval(h{3});
g=eval(h{4}); %执行一个完整的命令(字符串)
%***************************************************
a=location(1);
b=location(2);
alfa=alpha*pi/180; %弧度值转换U
tEnd=V0*sin(alfa)/g+((V0*sin(alfa)/g)^2+2*b/g)^0.5;%斜抛物体的运动时间
t=linspace(0,tEnd);
x=V0*cos(alfa)*t+a;%斜抛物体的水平位移
y=V0*sin(alfa)*t-0.5*g*t.^2+b;%斜抛物体的竖直位移
plot(x,y);%二维图像,画图
axis auto
comet(x,y);
grid;
hold on%从指令开始,将后续所有图形绘制在一个figure窗口中
xlabel 水平距离/m
ylabel 高度/m
title 斜抛轨迹
平抛:
vx = 10;
t = 0:0.001:10;
x = vx*t;
y = -9.8*t.^2/2;
comet(x,y)
你好,建议用animatedline函数,这样可以同时画两条线的动图:
%斜抛运动
clear; %清除所有变量
clc; %清屏
global location V0 alpha g; %定义全局变量
options={'初始位置(坐标)','初始速度V0' ,'抛射角度','重力加速度g',};
topic='seting';
lines=1; %输入框行数
def={'[0,0]','20','45','9.8'}; %初始值
h=inputdlg(options,topic,lines,def);%构造输入对话框
location=eval(h{1});
V0=eval(h{2});
alpha=eval(h{3});
g=eval(h{4}); %执行一个完整的命令(字符串)
%***************************************************
a=location(1);
b=location(2);
alfa=alpha*pi/180; %弧度值转换U
tEnd=V0*sin(alfa)/g+((V0*sin(alfa)/g)^2+2*b/g)^0.5;%斜抛物体的运动时间
t=linspace(0,tEnd,401);
x1=V0*cos(alfa)*t+a;%斜抛物体的水平位移
y1=V0*sin(alfa)*t-0.5*g*t.^2+b;%斜抛物体的竖直位移
vx = 10;
x2 = vx*t;
y2 = -9.8*t.^2/2;
figure(1)
xlabel 水平距离/m
ylabel 高度/m
title 斜抛轨迹
axis auto
grid;
hold on%从指令开始,将后续所有图形绘制在一个figure窗口中
h1 = animatedline('Color','r','LineWidth',2);
h2 = animatedline('Color','b','LineWidth',2);
axis([0 45 -50 20])
for k = 1:length(t)
addpoints(h1,x1(k),y1(k));
addpoints(h2,x2(k),y2(k));
drawnow
end
最终画图效果
有帮助还请给个采纳支持一下答主哟,谢谢啦