function flag=isClockwise(polygon)
%isClockwise determine if a polygon is clockwise or not.
%The logic is that the vertex farthest "out" will always lie on the convex
%hull along with its immediate neighbours. Thus checking its sign will
%reveal the winding order.
%The limitation is that this is non-robust to self intersecting polygons.

%   Copyright 2022 The MathWorks, Inc.

minY=min(polygon(:,2));
minIndices=find(polygon(:,2)==minY);
if(numel(minIndices)>1)
    maxX=max(polygon(minIndices,1));
    [~, index]=find(ismember(polygon,[maxX,minY],'rows'));
else
    index=minIndices;
end

flag=~uav.internal.coveragePlanner.isReflex(index,polygon);
end
