summaryrefslogtreecommitdiff
path: root/beam_tracing/python/fresnelReflection.py
blob: 2e4d4bcc3b5099d9f3f568fe8916b7b704a42725 (plain)
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
import numpy as np

def fresnelReflection(n1, n2, thetaInc):
# calculates intensity  reflection coefficient for s and p polarizations
# for light travelling from material with index of refraction n1 to 
# material with n2 
# theta_i - incident angle in medium 1 with respect to normal, could be a vector
# R       - coefficients of reflection array [Rs, Rp]
# theta_t - transmitted/refracted angle in medium 2 with respect to normal

   #if np.size(thetaInc, axis=0) != 1: 
    #  error('thetaInc must be a vector or scalar')
      
   # see  http://en.wikipedia.org/wiki/Fresnel_equations
   # refraction angle or angle of transmitted beam with respect to normal
   sinThetaTrans = n1 / n2 * np.sin(thetaInc)
   
   # special cases: total internal reflection
   if abs(sinThetaTrans) >= 1:
      sinThetaTrans = np.copysign(1, sinThetaTrans)
   thetaTrans = np.arcsin(sinThetaTrans) # angle of refraction


   cosThetaTrans = np.cos(thetaTrans)
   cosThetaInc = np.cos(thetaInc)

   Rs = ((n1 * cosThetaInc - n2 * cosThetaTrans) /\
         (n1 * cosThetaInc + n2 * cosThetaTrans)) ** 2
   Rp = ((n1 * cosThetaTrans - n2 * cosThetaInc) /\
         (n1 * cosThetaTrans + n2 * cosThetaInc)) ** 2
   R = np.array([[Rs], [Rp]])

   return [R, thetaTrans]