summaryrefslogtreecommitdiff
path: root/beam_tracing/make_beam_trace.m
blob: f62168f891689965a9f9777799fde2cee4a92a92 (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
function img=make_beam_trace(beam, stop_point, border_limits, img)
	% img so far beam traced part
	[Ny,Nx]=size(img);
	%% border_limits has coordinates of left bottom and right top coners
	xlb=border_limits(1);
	ylb=border_limits(2);
	xrt=border_limits(3);
	yrt=border_limits(4);

	%% beam start stop coordinates with respect to lower left border point
	xb1=beam.origin(1)-xlb;
	yb1=beam.origin(2)-ylb;
	xb2=stop_point(1)-xlb;
	yb2=stop_point(2)-ylb;

	%% beam path coordinates
	Nc=1000;  % number of coordinate points
	xb=linspace(xb1,xb2, Nc);
	yb=linspace(yb1,yb2, Nc);

	%% beam coordinate to image pixel coordinate
	px=round(xb/(xrt-xlb)*(Nx-1) + 1);
	py=round(yb/(yrt-ylb)*(Ny-1) + 1);

	%% truncate to borders
	py=py( (1<=px) & (px<=Nx) );
	px=px( (1<=px) & (px<=Nx) );

	px=px( (1<=py) & (py<=Ny) );
	py=py( (1<=py) & (py<=Ny) );

	for i=1:length(px)
		img(py(i),px(i))=beam.intensity;
	end
end