matlab 点光源经抛物面反射

% 点光源经抛物面反射
%function optical_reflect
set(gcf,"doublebuffer","on");
axis([-2,6,-5,5]);hold on
y = -4:0.01:4;
p = 1; %焦点
x = y.^2 / (4*p) - p;
plot(x,y,0,0,'r*');
Hi = plot([0,-2],[0,0],'b');%设置入射光
Hr = plot([-2,6],[0,0],'r');%设置反射光

xlabel('空格停止','fontsize',14,'color','r');
k=1;dy=0.1;%初始化k方便循环,设置入射光变化量
ty = 0;
while k
pause(0.1); %设置每个图形变换间隔0.1s
s = get(gcf,'currentkey');
if strcmp(s,'space')
    k=0;
end
if abs(ty) > 3
    dy = -dy;
end
ty=ty+dy;
tx=ty.^2 / (4*p) - p;
set(Hi,'xdata',[0,tx],'ydata',[0,ty]);
set(Hr,'xdata',[tx,6],'ydata',[ty,ty]);%绘制最后反射光
end

你可能感兴趣的:(matlab 点光源经抛物面反射)