function klic = trn_klic(x, y, xx, yy)
% klic = trn_klic(x(i,j), y, xx, yy)
%     i-ty klic, j-ty identicky bod (prave 2)
% klic(i,:) = [tx, ty, q, omega]

%% test vstupnich parametru
if nargin~=4
    error( 'Neplatny pocet vstupnich parametru!' )
end
if size(x,2)~=2 | size(y,2)~=2 | size(xx,2)~=2 | size(yy,2)~=2
    errot( 'Pocet identickych bodu jsou dva!' )
end
if size(x,1)~=size(y,1) | size(y,1)~=size(xx,1) | size(xx,1)~=size(yy,1)
    errot( 'Ruzny pocet dvojic identickych bodu!' )
end

%% vypocet
for i = 1:size(x,1)
    dx = x(i,2)-x(i,1);
    dy = y(i,2)-y(i,1);
    dxx = xx(i,2)-xx(i,1);
    dyy = yy(i,2)-yy(i,1);

    a1 = (dx*dxx + dy*dyy) / (dx^2+dy^2);
    a2 = (dxx*dy - dyy*dx) / (dx^2+dy^2);
    q = sqrt(a1^2 + a2^2);
    omega = atan2(a2, a1) * 200/pi;
    tx = xx(i,1) -a1*x(i,1) -a2*y(i,1);
    ty = yy(i,1) +a2*x(i,1) -a1*y(i,1);

    klic(i,:) = [tx, ty, q, omega];
end
