代码主体
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 24 09:30:12 2023
@author: Conway
"""
'''
@Default unit: mm
'''
#%% Diagram of the optical path
''' z3
\ \ :
* \ \ :
\ \ :
z1 z2
* light source
\ surface
: micron structure
'''
#%% import libraries
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('Qt5Agg')
import sys
sys.path.append(r'D:\Python program\Snells law')
import snell
#%% parameters
'''
z1: the front surface of substrate
z2: the rear surface of substrate
z3: the micron structrue vertex z-axis coordinate
n3 the refractive index between surface 2&3 (unable)
n2: the refractive index between surface 1&2
n1: the refractive index in front of surface 1
thickness: thickness of substrate
'''
thickness=0.25#constant
z1=2 #constant
z2=z1+thickness #iter
z3=z2+0.08 #iter
n1=1
n2=1.5
# n3=n2
#%%
'''
theta1: incident angle of substrate front surface
theta2: emergent angle of substrate front surface
h2: corresponding to z2, denoting the y coordinate
max_step: maxinum depth of the micron structure
shift: y-shift of (z2,h2)
cvector: denoting the emergent light direction on substrate rear surface
'''
theta2=np.arange(0,np.pi/180*41.5,1e-5)
theta1=np.arcsin(n2/n1*np.sin(theta2))
h2=0
y=np.array([])
z=y
max_step=0.08
shift=max_step/2
cvector=[0,1]
#%% parameters
'''
Radius: Radius of substrate
spread_degree: spread degree of the designed collimated light
center: focus coordinates of the designed collimated light
'''
radius=2
spread_degree=6
center=[0,z2-radius/np.tan(spread_degree/180*np.pi)] # collimating light focus
#%%
while h2<=radius:
temporary=np.array([float(h2),thickness+z1])-np.array(center)
angle=np.arctan2(temporary[0],temporary[1])
cvector=[float(np.sin