' matopt.bas - jack@ord.ca - revised 2 Oct 02 - Liberty Basic v3.01 ' matrix optics ray tracing program ' rays traced from an object in H(-) to its image in H'(-) Mainwin 80 30 dim p(10): dim q(10): p(8)=0: p(9)=0 cls : input "Index of incident medium = "; nleft input "Number of Matrices = "; m for j=1 TO m b11=0 input "Translation=1 Curved Surface=2 Plane Surface=3 Lens=4, Choice = "; z if z=1 then input "Displacement (+) = "; d b11=1: b12=0-d: b21=0: b22=1: p(9)=p(9)+d end if if z=2 then input "Radius (+/-) = "; d input "nright = "; nright b11=1: b12=0: b21=(nright-nleft)/(nleft*d): b22=nright/nleft nleft=nright end if if z=3 then input "nright = "; nright b11=1: b12=0: b21=0: b22=nright/nleft nleft=nright end if if z=4 then input "focal length (+/-) = "; f b11=1: b12=0: b21=1/f: b22=1 end if if b11=0 then print "Error": STOP if j=1 then a11=b11: a12=b12: a21=b21: a22=b22 else x11=a11*b11+a12*b21: x12=a11*b12+a12*b22 x21=a21*b11+a22*b21: x22=a21*b12+a22*b22 a11=x11: a12=x12: a21=x21: a22=x22 end if print "Matrix "; j; space$(12); b11; space$(15-len(str$(b11))); b12 print space$(20); b21; space$(15-len(str$(b21))); b22 next j print "O-O' Matrix "; a11; space$(15-len(str$(a11))); a12 print space$(20); a21; space$(15-len(str$(a21))); a22 det=a11*a22-a21*a12 print " Determinant = "; det if abs(a21)<.000001 then print "Telescopic System" print " Angular M = "; 1/a22 else d1=a11/a21: d2=a22/a21: f1=1/a21: f2=f1*det print "Positions of the focal points relative to O and O'" print space$(15); "OF = "; d1 print space$(14); "O'F = "; d2 print "The focal lengths f and f'" print space$(16); "f = "; f1 print space$(15); "f' = "; f2 print "Positions of the principal points relative to O and O'" print space$(15); "OH = "; d1-f1 print space$(14); "OH' = "; d2-f2 gosub [plot] wait end if end [plot] 'array index 0 to 9: H(-), F, H, N, N', H', F', H'(-), O, O' WindowWidth=610 ' pixel scale 0-600 WindowHeight=189 ' pixel scale 0-160 UpperLeftX=10: UpperLeftY=10 open "Ray Tracing" for graphics_nsb as #1 ' no slide bars p(0)=0-d1-f1: p(1)=0-d1: p(2)=f1-d1: p(3)=f2-d1 p(4)=p(9)+d2-f1: p(5)=p(9)+d2-f2: p(6)=p(9)+d2: p(7)=p(9)+d2+f2 xmin=p(0): xmax=p(0) for i=1 to 9 if p(i)xmax then xmax=p(i) next i xsc=500/(xmax-xmin) for i=0 to 9 q(i)=50+int((p(i)-xmin)*xsc+.5) next i #1 "down ; color lightgray ; backcolor lightgray" #1 "place "; q(8); " 0": #1 "boxfilled "; q(9); " 160" #1 "color black ; line 25 80 575 80" #1 "color blue ; line "; q(2); " 5 "; q(2); " 155" #1 "line "; q(5); " 5 "; q(5); " 155" if q(2)-12>q(8) and q(2)-12q(8) and q(5)+4q(8) and q(1)-12q(8) and q(6)+4q(8) and q(3)-12q(8) and q(4)+4