📄 refraction.m
字号:
function refraction;
% 光的折射
close all
figure;
set(gcf,'doublebuffer','on');
axis([-2,2,-1,1]);hold on;
rectangle('Position',[-2,-1,4,1],...
'FaceColor',[0.1,0.3,0.4]);
text(1.4,0.4,'air','color','r','fontsize',14)
text(1.4,-0.4,'glass','color','r','fontsize',14)
n=1.3;t=0;
text(0.7,0.6,['n= ',num2str(n)],'fontsize',14);
HL=rectangle('Position',[-0.02,0.4,0.04,0.2],...
'FaceColor',[0.1,0.3,0.4]);
Hi=plot([0,0],[0,0.4],'b');
Ho=plot([0,0],[0,-1]);
xlabel('Please press "space" key and stop this program!',...
'fontsize',14,'color','r');
k=1;dt=0.1;
while k
pause(0.1);
s=get(gcf,'currentkey');
if strcmp(s,'space');
clc;k=0;
end
if abs(t)>0.3*pi
dt=-dt;
end
t=t+dt;
A=t;
Xi=0.4*tan(A);
set(Hi,'xdata',[Xi,0]);
Ao=asin(sin(A)/n);
Xo=Xi+tan(Ao);
set(Ho,'xdata',[Xi,Xo]);
set(HL,'Facecolor',rand(1,3))
end
figure(gcf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -