You are on page 1of 4

Ray transfer matrix method

The ray transfer matrix method is a ray tracing technique used in the design
of dierent optical systems and lasers. It is used to model the eect of optical
elements such as simple lenses, aspheric lenses, gradient-index lenses, mirrors
and diractive optical elements. Methods similar to this have applications in
other elds including acoustics, electronics and accelerator physics as well to
track particles through the magnet installations of a particle accelerator.
With this method, any optical system can be described using a matrix called
the ray transfer matrix (also called the ABCD matrix). And a vector can be
the representative of a light ray. Then, the product of the ray vector and the
ray transfer matrix describes the path which the ray traces.
Consider a reference frame, in which the optical axis is along the z-axis,for
convenience.
Let R be a ray vector such that
 
x
R=
θ
This means that the ray passing through a point which is at a distance of
x units from the optical axis travels along a path which makes an angle θ with
the optical axis.
Say the ray vector changes to R0 after it passes through the system where
 0
x
R0 =
θ0
Then, the ray transfer matrix which represents the system, call it M , is
 
A B
M=
C D

Then

R0 = M R
 0   
x A B x
=
θ0 C D θ

1
The elements in the ray transfer matrix take dierent values for dierent
optical elements placed at dierent positions.
For instance, empty space is denoted by the matrix
 
1 d
MS =
0 1

A thin lens is denoted by the matrix


 
1 0
ML = −1
f 1

The ray transfer matrix for a combination of optical elements is simply the
product of the ray transfer matrices of the individual elements taken in the
right order. For instance, if a compound optical system consists of an element P
followed by an element Q and then an element R, it's ray transfer matrix would
be
M = MR MQ M P

The code follows :


import numpy as np
import m a t p l o t l i b . pyplot as p l t
import t k i n t e r as tk

n = 10 #number o f s l i c e s
d = 1 #width o f each s l i c e
t = . 2 #t h i c k n e s s o f the l e n s

#r e t u r n s a l i s t o f x v a l u e s
d e f x _ l i s t (R, opt ) :
x _ l i s t = [R. item ( 0 ) ]
f o r i i n range ( 1 , n+1):
R = np . matrix ( [ [ 1 , d ] , [ 0 , 1 ] ] ) ∗ R
i f i i n opt . keys ( ) and i != 0 :
R = opt [ i ] ∗ R
x _ l i s t . append (R. item ( 0 ) )
return x_list

#r e t u r n s the ray t r a n s f e r matrix


d e f RTM( opt ) :
M = np . matrix ( [ [ 1 , 0 ] , [ 0 , 1 ] ] )
f o r i i n range ( n , 0 , − 1 ) :
i f i i n opt . keys ( ) :
M ∗= opt [ i ]
M ∗= np . matrix ( [ [ 1 , d ] , [ 0 , 1 ] ] )
return M

2
#shows the l e n s e s
d e f l e n s ( opt , t ) :
f o r i i n opt :
i f opt [ i ] . item ( 2 ) != 0 :
r = −2/opt [ i ] . item ( 2 )
x1 = np . l i n s p a c e ( i , i+t , 100)
x2 = np . l i n s p a c e ( i −t , i , 100)
y = np . l i n s p a c e ( − 5 , 5 , 100)
X1 , Y = np . meshgrid ( x1 , y )
X2 , Y = np . meshgrid ( x2 , y )
F1 = (X1− i+r −t /2) ∗ ∗ 2 + Y∗∗ 2 − r ∗∗ 2
p l t . contour (X1 ,Y, F1 , [ 0 ] )
F2 = (X2−i −r+t /2) ∗ ∗ 2 + Y∗∗ 2 − r ∗∗ 2
p l t . contour (X1 ,Y, F1 , [ 0 ] )
p l t . contour (X2 ,Y, F2 , [ 0 ] )

#shows a ray
d e f ray (R, opt ) :
R0 = RTM( opt ) ∗ R
x = x _ l i s t (R, opt )
#ray path
p l t . p l o t ( l i s t ( range ( 0 , ( n+1) ∗ d , d ) ) , x )
#o p t i c a l − a x i s
p l t . p l o t ( l i s t ( range ( 0 , ( n+1) ∗ d , d ) ) , [ 0 ] ∗ ( n+1))
#o b j e c t
p l t . s c a t t e r ( 0 ,R. item ( 0 ) )
plt . plot ([0 ,0] ,[0 , x [ 0 ] ] )
#image
p l t . s c a t t e r ( n ∗ d , R0 . item ( 0 ) )
p l t . p l o t ( [ n∗d , n∗d ] , [ 0 , x [ n ] ] )
#shows l o t s a r a y s
d e f r a y s ( opt ) :
f o r n i n range ( − 5 ,6):
R = np . matrix ( [ [ n / 2 ] , [ 0 ] ] ) # ray v e c t o r
ray (R, opt )

#r e t u r n s a d i c t i o n a r y o f o p t i c a l elements with u s e r entry .


d e f opt_elements ( ) :
opt = {}
d e f add_lens ( ) :
opt [ i n t ( x . g e t ( ) ) ] = np . matrix ( [ [ 1 , 0 ] , [ − 1 / f l o a t ( f . g e t ( ) ) , 1 ] ] )
r o o t = tk . Tk ( )
r o o t . t i t l e ( ' M u l t i p l e l e n s e s can be added ' )

frame = tk . Frame ( r o o t )

3
frame . g r i d ( column=0, row=0, s t i c k y = tk .N+tk .W+tk . E+tk . S )
frame . columnconf igure ( 0 , weight =1)
frame . r o w c o n f i g u r e ( 0 , weight =1)

x = tk . StringVar ( )
x_entry = tk . Spinbox ( frame , from_=0, to =10, t e x t v a r i a b l e=x )
x_entry . g r i d ( column=2, row=1, s t i c k y =(tk .W, tk . E) )

f = tk . StringVar ( )
f_entry = tk . Entry ( frame , width =7, t e x t v a r i a b l e=f )
f_entry . g r i d ( column=2, row=2, s t i c k y =(tk .W, tk . E) )

tk . Label ( frame , t e x t="P o s i t i o n : " ) . g r i d ( column=1, row=1, s t i c k y=tk .W)


tk . Label ( frame , t e x t="Focal l e n g t h : " ) . g r i d ( column=1, row=2, s t i c k y=tk .W)

tk . Button ( frame , t e x t="Add l e n s " , command = add_lens ) . g r i d ( column=3, row=


tk . Button ( frame , t e x t="Show image " , command = r o o t . d e s t r o y ) . g r i d ( column=2

f o r c h i l d i n frame . w i n f o _ c h i l d r e n ( ) : c h i l d . g r i d _ c o n f i g u r e ( padx=5, pady=5)

r o o t . bind ( ' < Return > ' , add_lens )


r o o t . mainloop ( )
r e t u r n opt

opt = opt_elements ( )
r a y s ( opt )
l e n s ( opt , t )
p l t . show ( )

You might also like