function extended_mirror(ground, height, src, mic)
% priklad volani: extended_mirror([0 2 10 10 2;0 3 4 -4 -3],5,[4 1 1],[9 -1 2])
% ground = dvojrozmerne pole souradnic rohu v mistnosti, body zadavane po smeru hodinovych rucicek, pricemz jeden roh zvolen jako pocatek 0,0
%		  treti rozmer je dan vyskou mistnosti - (mistnosti jako mnohostenne hranoly)
%		  priklad zadani [0 2 10 10 2;0 3 4 -4 -3]
% height = vyska mistnosti
% src = souradnice zdroje
% mic = souradnice prijimace
% c = rychlost zvuku m/s
% src = input("Zadejte souradnice zdroje: "); %pro pripadne definovani vstupu
tic
clc;
c = 343;

corners = length(ground)
if corners < 3
	error('Ze dvou rohu nelze sestavit mistnost, minimalni pocet jsou tri');
end 
if height == 0
	error('Vyska mistnosti musi byt nenulova');
end
height = height * ones(1,corners);
room = [ground ground ; zeros(1,corners) height] % kompletni souradnice rohu mistnosti
%VS = zeros(3,1);

level = 1;
tmp_l = 1;
walls = [];
[VS, vsrc_mic_dist, image_time, sound_level, level, walls] = recurse(corners,room,src,mic,height,level,tmp_l,walls);


% vypocty pro originalni zdroj
src_mic_dist = norm(src - mic);
direct_time = src_mic_dist / c;
sound_level_orig = 100 / (src_mic_dist * src_mic_dist);

sound_level_b = sound_level;

for i = 1:length(VS)
	tmp = find(image_time == image_time(i));
	sound_sum(i) = sum(sound_level(tmp));
	sound_level(tmp) = 0;
end
sound_sum;

% celkove vysledky
info = ['    x' ; '    y' ; '    z' ; 'vzdalenost' ; '   cas' ; 'intenzita'; 'pocet sten'];
results = [src' VS  ; src_mic_dist vsrc_mic_dist ; direct_time image_time ; sound_level_orig sound_level_b; 0 walls]
id_result = fopen('results.txt', 'w');
fdisp(id_result,results);
fclose(id_result);

h = [[direct_time image_time]; [sound_level_orig sound_sum]];
% je nutne seradit impulzy podle casu
[time, ii] = sort(h(1,:));
hh = h(2,ii);

auralize(hh,'impulse.wav','impulse.txt','five.wav','auralized.wav');

x = stem([direct_time image_time], [sound_level_orig sound_sum]);
set(x,'marker','.')
title('')
xlabel('cas [s]')
ylabel('intenzita zvuku [%]')
grid
print('figimp.eps','-deps')

toc