function [n_x,n_y,surfJ] = Normals2D_my()

Globals2D;

n_x = zeros(N_faces * N_fp,K); n_y = zeros(N_faces * N_fp,K);
faceIDs = [(1:N_fp)', ((N_fp + 1):(2 * N_fp))', ((2 * N_fp + 1):(3 * N_fp))'];
face_def = [1, 2; 2, 3; 3, 1];

for i = 1:N_faces
    face = face_def(i,:);
    
    % smerove a normalove vektory
    t_matrix = [P(1,E(face(1),:)) - P(1,E(face(2),:)); P(2,E(face(1),:)) - P(2,E(face(2),:))];
    n_matrix = [-t_matrix(2,:);t_matrix(1,:)];
    
    % otoceni vnitrnich normal
    const_vect = -(n_matrix(1,:) .* P(1,E(face(1),:)) + n_matrix(2,:) .* P(2,E(face(1),:)));
    pointID = setdiff(1:3,face);
    points = [P(1,E(pointID,:));P(2,E(pointID,:))];
    signs = n_matrix(1,:) .* points(1,:) + n_matrix(2,:) .* points(2,:) + const_vect;
    IDs = (signs > 0);
    n_matrix(:,IDs) = -n_matrix(:,IDs);
    
    % zapsani do n_x a n_y
    n_x(faceIDs(:,i),:) = repmat(n_matrix(1,:),N_fp,1);
    n_y(faceIDs(:,i),:) = repmat(n_matrix(2,:),N_fp,1);
end

surfJ = sqrt(n_x .* n_x + n_y .* n_y);
n_x = n_x ./ surfJ; n_y = n_y ./ surfJ;
surfJ = surfJ / 2; % protoze puvodne byly smerove vektory jen poloviny stran

end