function b = NE_already_inverted_pent(pent,inverted)
% NE_already_inverted_pent - check if pentagon already inverted
% On input:
%     pent (5x2 array): vertexes of a pentagon
%     inverted (nx10 array): linear form of already inverted pentagons
% On output:
%     b (Boolean): 1 if already inverted; else 0
% Call:
%     if NE_already_inverted_pent(pp,inv)
% Author:
%     T. Henderson
%     UU
%     Summer 2023
%

b = 0;

[num_inverted,~] = size(inverted);
poly1 = polyshape([pent(:,1);pent(1,1)],[pent(:,2);pent(1,2)]);
A1 = polyarea(poly1.Vertices(:,1),poly1.Vertices(:,2));

for k = 1:num_inverted
    p_k = reshape(inverted(k,:),5,2);
    poly2 = polyshape([p_k(:,1);p_k(1,1)],[p_k(:,2);p_k(1,2)]);
    polyi = intersect(poly1,poly2);
    A2 = polyarea(poly2.Vertices(:,1),poly2.Vertices(:,2));
    Ai = polyarea(polyi.Vertices(:,1),polyi.Vertices(:,2));
    if A1/A2>0.9&Ai/A1>0.5
        b = 1;
        return
    end
    tch = 0;
end
