how to calculate incidence angle of photon given direction vector and boundary normal in matlab

The angle of incidence can be calculated as the angle between the direction vector and the boundary normal.

Assuming your direction vector is represented by d and the boundary normal is represented by n, you can use MATLAB's dot function to obtain the dot product of these two vectors. The dot product gives you the cosine of the angle between the two vectors. You can then use acos function to obtain the angle in radians.

Here's the MATLAB code to calculate the incidence angle:

main.m
% Example direction vector
d = [1, 2, 3]; 
% Example boundary normal
n = [-1, 2, -2];

% Normalize the vectors
d = d / norm(d);
n = n / norm(n);

% Calculate the incidence angle in radians
theta = acos(dot(d,n));
213 chars
12 lines

Note that the dot function assumes that the vectors are column vectors, so you may need to transpose them if they are row vectors.

gistlibby LogSnag