理想情况下3个能量守恒定律 动画演示
pole=1.8;%定义摆线的长度
xmax=2;%定义横坐标长度
ymax=2;%定义纵坐标长度
basew=2.3;%定义图中方框的宽度
baseh=2.3;%定义图中方框的高度
instant=0.2;%定义摆线间距
%三视图的初始设置
%第一幅图
figure('name','理想情况下能量守恒定律1','position',[500,340,440,320]);%定义第一幅图的标题和位置
fill([xmax,xmax,-xmax,-xmax,xmax,xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05,xmax-0.05],[ymax,-ymax,-ymax,ymax,ymax,ymax-0.05,-ymax+0.05,-ymax+0.05,ymax-0.05,ymax-0.05],[0,1,1]);
%填充底座背景
hold on;%保持当前图形及坐标所有特性
fill([xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05],[ymax-0.5 ,ymax-0.55,ymax-0.55,ymax-0.5],'g');%填充方框内横杆背景
hold on;%保持当前图形及坐标所有特性
text(-0.25,1.7,'1');text(0,1.7,'2');text(0.25,1.7,'3');%在坐标处标识说明文字
text( -1.0,1.7,'a');text( -1.0,-1.7,'b');%在坐标处标识说明文字
text(1.0,1.7,'真空容器');text(-1.8,1.7,'主视图');%在坐标处标识说明文字
axis([-basew,basew,-baseh,baseh]);%定义背景坐标范围在x(-2.3~2.3) Y(-2.3~2.3)之间
%axis('off');%覆盖坐标刻度并填充背景
theta0=7 *pi/6;%摆线1的初始角度
x0=pole*cos(theta0);%摆线1末端x坐标
y0=pole*sin(theta0)+1.5;%摆线1末端y坐标
body1=line([-instant,x0-instant],[1.5,y0],'color','r','linestyle','-','erasemode','xor');%设置摆线1
head1=line(x0-instant,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);%设置第一个小球颜色,大小
theta1=3*pi/2;%摆线2,3的角度
x1=pole*cos(theta1);%摆线2,3末端x坐标
y1=pole*sin(theta1)+1.5;%摆线2,3末端y坐标
body=line([-0.001,x1],[1.5,y1],'color','k','linestyle','-','erasemode','xor');%设置摆线2
head=line(x1,y1,'color','k','linestyle','.','erasemode','xor','markersize',40);%设置第2个小球颜色,大小
body2=line([instant;x1+instant],[1.5;y1],'color','b','linestyle','-','erasemode','xor');%设置摆线3
head2=line(x1+instant,y1,'color','b','linestyle','.','erasemode','xor','markersize',40);%设置第3个小球颜色,大小
theta3=15*pi/6 ;
%第二幅图
figure('name','理想情况下能量守恒定律2','position',[500,40,440,320]);%定义第一幅图的标题和位置
fill([xmax,xmax,-xmax,-xmax,xmax,xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05,xmax-0.05],[ymax,-ymax,-ymax,ymax,ymax,ymax-0.05,-ymax+0.05,-ymax+0.05,ymax-0.05,ymax-0.05],[0,1,1]);
%填充底座背景
hold on;%保持当前图形及坐标所有特性
fill([xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05],[ymax-0.5 ,ymax-0.55,ymax-0.55,ymax-0.5],'g');%填充方框内第一根横杆背景
hold on;%保持当前图形及坐标所有特性
fill([xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05],[-ymax+0.55 ,-ymax+0.5,-ymax+0.5,-ymax+0.55 ],'b');%填充方框内第二根横杆背景
hold on;%保持当前图形及坐标所有特性
text(-0.25,1.7,'1');text(0,1.7,'2');text(0.25,1.7,'3');%在坐标处标识说明文字
text( -1.0,1.7,'a');text( -1.0,-1.7,'b');%在坐标处标识说明文字
text(1.0,1.7,'真空容器');text(-1.8,1.7,'俯视图');%在坐标处标识说明文字
axis([-basew,basew,-baseh,baseh]);%定义背景坐标范围在x(-2.3~2.3) Y(-2.3~2.3)之间
%axis('off');%覆盖坐标刻度并填充背景
y01=0;%设置摆球纵坐标值
body11=line([-instant,x0-instant],[1.5,y01],'color','r','linestyle','-','erasemode','xor');%设置摆线1上摆线
body12=line([-instant,x0-instant],[-1.5,y01],'color','r','linestyle','-','erasemode','xor');%设置摆线1下摆线
head01=line(x0-instant,y01,'color','r','linestyle','.','erasemode','xor','markersize',40);%设置第一个小球颜色,大小
body01=line([-0.001,x1],[1.5,y01],'color','k','linestyle','-','erasemode','xor');%设置摆线2上摆线
body02=line([-0.001,x1],[-1.5,y01],'color','k','linestyle','-','erasemode','xor');%设置摆线2下摆线
head00=line(x1,y01,'color','k','linestyle','.','erasemode','xor','markersize',40);%设置第二个小球颜色,大小
body21=line([instant;x1+instant],[1.5;y01],'color','b','linestyle','-','erasemode','xor');%设置摆线3上摆线
body22=line([instant;x1+instant],[-1.5;y01],'color','b','linestyle','-','erasemode','xor');%设置摆线3下摆线
head02=line(x1+instant,y01,'color','b','linestyle','.','erasemode','xor','markersize',40);%设置第三个小球颜色,大小
%第三幅图
figure('name','理想情况下能量守恒定律3','position',[50,340,440,320]);%定义第三幅图的标题和位置
fill([xmax,xmax,-xmax,-xmax,xmax,xmax-0.05,xmax-0.05,-xmax+0.05,-xmax+0.05,xmax-0.05],[ymax,-ymax,-ymax,ymax,ymax,ymax-0.05,-ymax+0.05,-ymax+0.05,ymax-0.05,ymax-0.05],[0,1,1]);
%填充底座背景
hold on%保持当前图形及坐标所有特性
text(1.0,1.7,'真空容器');text(-1.8,1.7,'侧视图');%在坐标处标识说明文字
text( -1.7,1.5,'a');text( 1.7,1.5,'b');%在坐标处标识说明文字
axis([-basew,basew,-baseh,baseh]);%定义背景坐标范围在x(-2.3~2.3) Y(-2.3~2.3)之间
%axis('off');%覆盖坐标刻度并填充背景
x01=0;x02=1.48;y02=1.48;%设置坐标
head000=line(-x02,y02,'color','g','linestyle','.','erasemode','xor','markersize',18);%设置横杆a
head000=line(x02,y02,'color','g','linestyle','.','erasemode','xor','markersize',18);%设置横杆b
body311=line([-x02,x01],[y02,y0],'color','r','linestyle','-','erasemode','xor');%设置摆线1上摆线
body312=line([x02,x01],[y02,y0],'color','r','linestyle','-','erasemode','xor');%设置摆线1下摆线
head301=line(x01,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);%设置摆球1
body301=line([-x02,x01],[y02,y1],'color','k','linestyle','-','erasemode','xor');%设置摆线2上摆线
body302=line([x02,x01],[y02,y1],'color','k','linestyle','-','erasemode','xor');%设置摆线2下摆线
head300=line(x01,y1,'color','k','linestyle','.','erasemode','xor','markersize',40);%设置摆球2
body321=line([-x02;x01],[y02;y1],'color','b','linestyle','-','erasemode','xor');%设置摆线3上摆线
body322=line([x02;x01],[y02;y1],'color','b','linestyle','-','erasemode','xor');%设置摆线3下摆线
head302=line(x01,y1,'color','b','linestyle','.','erasemode','xor','markersize',40);%设置摆球3
while 1%条件判断
theta0=theta0+pi/540;
theta3=theta3-pi/540;
if theta0>=15*pi/6
theta0=7*pi/6;
theta3=15*pi/6 ;
%设置摆球1运动过程
elseif (theta0>=7*pi/6)&(theta0<3*pi/2)
x11=pole*cos(theta0);
y11=pole*sin(theta0)+1.5;
set(body1,'xdata',[-instant,x11-instant],'ydata',[1.5,y11]);%设置主视图中摆线1运动
set(head1,'xdata',x11-instant,'ydata',y11);%设置主视图中摆球1运动
set(body11,'xdata',[-instant,x11-instant],'ydata',[1.5,y01]);%设置俯视图中摆线1上摆线运动
set(body12,'xdata',[-instant,x11-instant],'ydata',[1.5,y01]);%设置俯视图中摆线1下摆线运动
set(head01,'xdata',x11-instant,'ydata',y01);%设置俯视图中摆球1运动
set(body311,'xdata',[-x02,x01],'ydata',[y02,y11]);%设置侧视图中摆线1上摆线运动
set(body312,'xdata',[x02,x01],'ydata',[y02,y11]);%设置侧视图中摆线1下摆线运动
set(head301,'xdata',x01,'ydata',y11);%设置侧视图中摆球1运动
%设置摆球3运动的过程
elseif (theta0>=3*pi/2)&(theta0<11*pi/6)
x22=pole*cos(theta0);
y22=pole*sin(theta0)+1.5;
set(body2,'xdata',[instant,x22+instant],'ydata',[1.5,y22]);%设置主视图中摆线3运动
set(head2,'xdata',x22+instant,'ydata',y22);%设置主视图中摆球3运动
set(body21,'xdata',[instant,x22+instant],'ydata',[1.5,y01]);%设置俯视图中摆线3上摆线运动
set(body22,'xdata',[instant,x22+instant],'ydata',[-1.5,y01]);%设置俯视图中摆线3下摆线运动
set(head02,'xdata',x22+instant,'ydata',y01);%设置俯视图中摆球3运动
set(body321,'xdata',[-x02,x01],'ydata',[y02,y22]); %设置侧视图中摆线3上摆线运动
set(body322,'xdata',[x02,x01],'ydata',[y02,y22]);%设置侧视图中摆线3下摆线运动
set(head302,'xdata',x01,'ydata',y22);%设置侧视图中摆球3运动
% 设置摆球3运动过程
elseif (theta0>=11*pi/6 )&(theta0<=13*pi/6 )
x32=pole*cos(theta3);
y32=pole*sin(theta3)+1.5;
set(body2,'xdata',[instant,x32+instant],'ydata',[1.5,y32]);%设置主视图中摆线3运动
set(head2,'xdata',x32+instant,'ydata',y32);%设置主视图中摆球3运动
set(body21,'xdata',[instant,x32+instant],'ydata',[1.5,y01]);%设置俯视图中摆线3上摆线运动
set(body22,'xdata',[instant,x32+instant],'ydata',[-1.5,y01]);%设置俯视图中摆线3下摆线运动
set(head02,'xdata',x32+instant,'ydata',y01);%设置俯视图中摆球3运动
set(body321,'xdata',[-x02,x01],'ydata',[y02,y32]); %设置侧视图中摆线3上摆线运动
set(body322,'xdata',[x02,x01],'ydata',[y02,y32]);%设置侧视图中摆线3下摆线运动
set(head302,'xdata',x01,'ydata',y32);%设置侧视图中摆球3运动
%设置摆球1运动过程
elseif (theta0>=13*pi/6 )&(theta0<15*pi/6 )
x41=pole*cos(theta3);
y41=pole*sin(theta3)+1.5;
set(body1,'xdata',[-instant,x41-instant],'ydata',[1.5,y41]);%设置主视图中摆线1运动
set(head1,'xdata',x41-instant,'ydata',y41);%设置主视图中摆球1运动
set(body11,'xdata',[-instant,x41-instant],'ydata',[1.5,y01]);%设置俯视图中摆线1上摆线运动
set(body12,'xdata',[-instant,x41-instant],'ydata',[-1.5,y01]);%设置俯视图中摆线1下摆线运动
set(head01,'xdata',x41-instant,'ydata',y01);%设置俯视图中摆球1运动
set(body311,'xdata',[-x02,x01],'ydata',[y02,y41]);%设置侧视图中摆线1上摆线运动
set(body312,'xdata',[x02,x01],'ydata',[y02,y41]);%设置侧视图中摆线1下摆线运动
set(head301,'xdata',x01,'ydata',y41); %设置侧视图中摆球1运动
drawnow;
end
end

浙公网安备 33010602011771号