Home > atmlab > physics > snell.m

snell

PURPOSE ^

SNELL Snell's law

SYNOPSIS ^

function theta2 = snell(n1,n2,theta1)

DESCRIPTION ^

 SNELL   Snell's law

    Calculates the angle of the transmitted wave, according to Snell's law.  

    Snell's law for the case when both *n1* and *n2* have no imaginary part
    is found in all physics handbooks. 

    The expression for complex *n2* is taken from "An introduction to
    atmospheric radiation" by K.N. Liou (Sec. 5.4.1.3).

    No expression that allows *n1* to be complex has been found.

    If theta2 is found to be complex, it is returned as NaN. This can happen
    when n1 > n2, and corresponds to a total reflection and there is no
    transmitted part.

    The refractive index and the dielectric constant, epsilon, are releated 
    as

      n = sqrt(epsilon)

 FORMAT   theta2 = snell(n1,n2,theta1)
        
 OUT   theta2   Angle for transmitted part.
 IN    n1       Refractive index for medium of incoming radiation.
       n2       Refractive index for reflecting medium.
       theta1   Angle between surface normal and incoming radiation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

snell.m

SOURCE CODE ^

0001 % SNELL   Snell's law
0002 %
0003 %    Calculates the angle of the transmitted wave, according to Snell's law.
0004 %
0005 %    Snell's law for the case when both *n1* and *n2* have no imaginary part
0006 %    is found in all physics handbooks.
0007 %
0008 %    The expression for complex *n2* is taken from "An introduction to
0009 %    atmospheric radiation" by K.N. Liou (Sec. 5.4.1.3).
0010 %
0011 %    No expression that allows *n1* to be complex has been found.
0012 %
0013 %    If theta2 is found to be complex, it is returned as NaN. This can happen
0014 %    when n1 > n2, and corresponds to a total reflection and there is no
0015 %    transmitted part.
0016 %
0017 %    The refractive index and the dielectric constant, epsilon, are releated
0018 %    as
0019 %
0020 %      n = sqrt(epsilon)
0021 %
0022 % FORMAT   theta2 = snell(n1,n2,theta1)
0023 %
0024 % OUT   theta2   Angle for transmitted part.
0025 % IN    n1       Refractive index for medium of incoming radiation.
0026 %       n2       Refractive index for reflecting medium.
0027 %       theta1   Angle between surface normal and incoming radiation.
0028 
0029 % 2010-01-28   Created by Patrick Eriksson.
0030 
0031 
0032 function theta2 = snell(n1,n2,theta1)
0033 %                                                                           %&%
0034 rqre_nargin( 3, nargin );                                                   %&%
0035 rqre_datatype( n1, @isnumeric );                                            %&%
0036 rqre_datatype( n2, @isnumeric );                                            %&%
0037 rqre_datatype( theta1, @isnumeric );                                        %&%
0038 rqre_element_math( n1, n2 );                                                %&%
0039 rqre_element_math( n1, theta1 );                                            %&%
0040 if real(n1)<=0 | real(n2)<=0                                                %&%
0041   error( 'The real part of *n1* and *n2* can not be <= 0.' );               %&%
0042 end                                                                         %&%
0043 
0044 
0045 isr1 = isreal( n1 );
0046 isr2 = isreal( n2 );
0047 
0048 DEG2RAD = constants( 'DEG2RAD' );
0049 RAD2DEG = constants( 'RAD2DEG' );
0050 
0051 
0052 if isr1 & isr2
0053   theta2 = asin( n1 .* sin( DEG2RAD * theta1 ) ./ n2 );
0054   if isreal( theta2 )
0055     theta2 = RAD2DEG * theta2;
0056   else
0057     theta2 = NaN;
0058   end
0059   
0060 elseif isr1
0061   mr2  = ( real(n2) ./ n1 ).^2;
0062   mi2  = ( imag(n2) ./ n1 ).^2;
0063   sin1 = sin( DEG2RAD * theta1 );
0064   s2   = sin1 .* sin1; 
0065   Nr   = sqrt( ( mr2-mi2+s2 + sqrt( (mr2-mi2-s2).^2 + 4*mr2.*mi2 ) ) / 2.0 );
0066   theta2 = asin( sin1 ./ Nr );
0067   if isreal( theta2 )
0068     theta2 = RAD2DEG * theta2;
0069   else
0070     theta2 = NaN;
0071   end
0072   
0073 else
0074   error( 'No expression implemented for imaginary *n1*.' );
0075 end
0076

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005