function [pt,d]=project1(r) hold off; % Initialization p0=[0.6;0.1]; v=[1;0]; T=10; r=1/3; % Computation [ptmp,vtmp,t]=nextpoint(p0,v,T,r); hold on; axis equal; iter=0; while t r) && (t < T), t=t+dt; ptmp=ptmp+dt*v; p0c=round(ptmp); rtmp=norm(ptmp-p0c); end % once we have found the circle where the photon is going to hit upon, we can % find the point where the photon hits the circle by solving a quadratic % equation about the hitting time. if rtmpT) pt=p0+T*v; vt=v; t=T; else pt=p0+t*v; vt=nextvelocity(v,pt,p0c,r); end % now plot the path and the circle h=0.01; tp=0:h:t; x1=p0(1)+v(1)*tp; y1=p0(2)+v(2)*tp; theta=0:h:2*pi; x2=p0c(1)+r*cos(theta); y2=p0c(2)+r*sin(theta); plot(x1,y1,'r-',x2,y2,'b-') function vt=nextvelocity(v,p,p0c,r) % given the incident velocity, the reflecting point, and the center of the % circle, compute the reflected velocity by Householder reflector. a=p-p0c; vt=v-2*(a'*v)/(a'*a)*a;