-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsust_phy_abcd.py
207 lines (177 loc) · 6.08 KB
/
sust_phy_abcd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Python Package sust_phy_abcd
# Author: Tahmidul Azom Sany
# Created for Computational Physics course of SUST Physics
# Under the supervision of Dr. Md Enamul Hoque(Assistant Professor, SUST)
from numpy import *
from math import *
def distance(d):
"""
This function creates an ray transfer matrix for d distance
input:
distance(50)
output:
The ray transfer matrix for your setup at d distance is
[[ 1. 50.]
[ 0. 1.]]
"""
arr01 = array([
[1, d],
[0, 1]
], float)
print("The ray transfer matrix for your setup at d distance is", )
print(arr01)
#---------------------------------------------------------------------------------------------
def thinlens(f):
"""
This function creates an ray transfer matrix for a lens with f focal length
input:
thinlens(50)
output:
The ray transfer matrix for your thin lens of focal lenth f is
[[ 1. 0. ]
[-0.02 1. ]]
"""
arr02 = array([
[1, 0],
[-1/f, 1]
])
print("The ray transfer matrix for your thin lens of focal lenth f is", )
print(arr02)
#---------------------------------------------------------------------------------------------
def refraflat(n1 ,n2):
"""
This function creates an ray transfer matrix for refraction in a flat interface
n1 = initial refractive index
n2 = final refractive index
Example:
source code is -> refraflat(n1, n2)
Input:
refraflat(4,2)
Output:
The ray transfer matrix for refraction in a flat interface is
[[1. 0.]
[0. 2.]]
"""
arr03 = array([
[1, 0],
[0, n1/n2]
], float)
print("The ray transfer matrix for refraction in a flat interface is ")
print(arr03)
#----------------------------------------------------------------------------------------------
def refracurve(n1, n2, R):
"""
This function creates an ray transfer matrix for a refraction at a curved interface
Example:
n1 = initial refractive index
n2 = final refractive index
R = radius of curvature
source code is -> refracurve(n1, n2, R)
Input:
refracurve(4,2,3)
Output:
The ray transfer matrix for refraction at a curved interface is
[[1. 0. ]
[0.33333333 2. ]]
"""
arr04 = array([
[1, 0],
[(n1-n2)/(R*n2), n1/n2]
], float)
print("The ray transfer matrix for refraction at a curved interface is ")
print(arr04)
#----------------------------------------------------------------------------------------------
def refflatmirror():
"""
This function creates an ray transfer matrix for reflection from a flat mirror.
You don't need to create any input here.
input:
refflatmirror()
output:
The ray transfer matrix for reflaction in a flat interface is
[[1. 0.]
[0. 1.]]
"""
arr05 = array([
[1, 0],
[0, 1]
], float)
print("The ray transfer matrix for reflaction in a flat interface is ")
print(arr05)
#----------------------------------------------------------------------------------------------
def refracurvemirror(Re):
"""
This function creates an ray transfer matrix for refraction in a curved mirror.
You just need to enter effective radius of curvature, Re in the bracket.
Example:
source code is -> refracurvemirror(Re):
input:
refracurvemirror(4)
output:
The ray transfer matrix for refraction at a curved mirror is
[[ 1. 0. ]
[-0.5 1. ]]
and it will provide a ray transfer matrix for refraction in a curved mirror.
"""
arr06 = array([
[1, 0],
[-2/Re, 1]
], float)
print("The ray transfer matrix for refraction at a curved mirror is ")
print(arr06)
#----------------------------------------------------------------------------------------------
def sinpri(k, d, n):
"""
This function creates an ray transfer matrix for single prism. You just need to enter k,d,n
here,
k = cos(a)/cos(b) --> You have to calculate this.
a = the angle of refraction(in radian)
b = the angle of incidence(in radian)
d = Prism path length
n = Refractive index of the prism material
Example:
Source code-->sinpri(k,d,n)
This matrix applies for orthogonal beam exit
input:
sinpri(2,4,3)
output:
The ray transfer matrix for a single prism is:
[[2. 0.66666667]
[0. 0.5 ]]
"""
arr07 = array([
[k, d/(n*k)],
[0, 1/k]
], float)
print("The ray transfer matrix for a single prism is: ")
print(arr07)
#----------------------------------------------------------------------------------------------
def mulpri(n, B, *k):
"""
This function creates an ray transfer matrix for multiple prism. You just need to enter n, B in the bracket.
here,
n = the number of prism you are using
B = the total optical propagation distance of the multiple prism expander
After inputing the first two argument in the code, the program will ask you to put the value of k.
Example:
input:
mulpri(3, 2)
output:
Enter the beam expansion factor, k=2
Enter the beam expansion factor, k=3
Enter the beam expansion factor, k=4
The ray transfer matrix for a multiple prism is:
[[24. 2. ]
[ 0. 0.04166667]]
>
"""
M = 1
for i in range(n):
k = float(input("Enter the beam expansion factor, k=", ))
M = k*M
arr08 = array([
[M, B],
[0, 1/M]
], float)
print("The ray transfer matrix for a multiple prism is: ")
print(arr08)