From e4360a48435cc762855d356b208b5544e6f40c4b Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Thu, 28 Feb 2013 14:59:55 -0500 Subject: Added python version of mode-matching code by Bain Bronner --- beam_tracing/python/fresnelReflection.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 beam_tracing/python/fresnelReflection.py (limited to 'beam_tracing/python/fresnelReflection.py') diff --git a/beam_tracing/python/fresnelReflection.py b/beam_tracing/python/fresnelReflection.py new file mode 100644 index 0000000..2e4d4bc --- /dev/null +++ b/beam_tracing/python/fresnelReflection.py @@ -0,0 +1,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] \ No newline at end of file -- cgit v1.2.3