summaryrefslogtreecommitdiff
path: root/fresnel_reflection.m
blob: 0e6dfdcb609977b1f8d57ae441e1dc785f851d9e (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
function [R, theta_t] = fresnel_reflection(n1, n2, theta_i)
%% 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
%% R - coefficients of reflection array [Rs, Rp]
%% theta_t - transmitted/refracted angle in medium 2 with respect to normal

	%% see  http://en.wikipedia.org/wiki/Fresnel_equations
	%% refraction angle or angle of transmitted beam with respect to normal
	sin_theta_t=n1/n2*sin(theta_i);

	if ( abs(sin_theta_t) >= 1)
		%% total internal reflection
		R = [1, 1];
		theta_t=sign(theta_i)*pi/2;
		return;
	end

	theta_t = asin(sin_theta_t); % angle of refraction or transmitted beam

	cos_theta_t = cos( theta_t );
	cos_theta_i = cos( theta_i );

	Rs = ( ( n1*cos_theta_i - n2*cos_theta_t ) / ( n1*cos_theta_i + n2*cos_theta_t ) ).^2;
	Rp = ( ( n1*cos_theta_t - n2*cos_theta_i ) / ( n1*cos_theta_t + n2*cos_theta_i ) ).^2;
	R = [Rs,Rp];
end