summaryrefslogtreecommitdiff
path: root/gbeam_propagation_froward_only.m
blob: ba8c1cf9d92e335b5d9f9cb9d8713a9db3eafb8f (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
34
35
36
37
38
39
40
function q = gbeam_propagation_froward_only(x_pos, q_in, x_in,  optics_elements)
% calculate the 'q' parameter of the Gaussian beam propagating through optical
% 'optics_elements' only in the positive direction  along 'x' axis at points 'x_pos'
% takes the gaussian beam with initial q_in parameter at x_in
%
% all x_pos must be to the right of x_in
% x_pos must be monotonic!
	if (any(x_pos < x_in))
		error('all beam positions must be to the right of the x_in');
	end

	optics_elements=arrange_optics_along_x(optics_elements);

	% Forward propagation to the right of x_in
	Np=length(x_pos); % number of 'x' points
	Nel=length(optics_elements) ;
	q=0*x_pos; % q vector initialization
	q_last_calc=q_in;
	x_last_calc=x_in; % the furthest calculated point
	for i=1:Np
		x_pos_i=x_pos(i);
		for k=1:length(optics_elements) 
			% iterates through optics_elements to make sure 
			% we take them in account for the beam propagation
			el=optics_elements{k};
			if ( (x_last_calc < el.x) && (el.x <= x_pos_i) )
				abcd=abcd_free_space(el.x-x_last_calc);
				q_last_calc=q_afteer_element(q_last_calc,abcd);
				q_last_calc=q_afteer_element(q_last_calc,el.abcd);
				x_last_calc=el.x;
			endif
		endfor
		if (x_pos_i > x_last_calc);
			abcd=abcd_free_space(x_pos_i-x_last_calc);
			q_last_calc=q_afteer_element(q_last_calc,abcd);
			x_last_calc=x_pos_i;
		endif
		q(i)=q_last_calc;
	endfor
end