function value = polygon_is_ccw ( v )

%*****************************************************************************80
%
%% polygon_is_ccw() determines whether a polygon is counter clockwise.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real V(N,2), the coordinates of the vertices of the polygon.  
%
%  Output:
%
%    logical VALUE: true if the polygon vertices are listed in CCW order.
%
  n = size ( v, 1 );

  value = true;

  for i = 1 : n

    j = mod ( i, n ) + 1;
    k = mod ( i + 1, n ) + 1;

    dot =   ( v(k,1) - v(j,1) ) * ( v(i,1) - v(j,1) ) ...
          + ( v(k,2) - v(j,2) ) * ( v(i,2) - v(j,2) );

    cross =   ( v(k,1) - v(j,1) ) * ( v(i,2) - v(j,2) ) ...
            - ( v(i,1) - v(j,1) ) * ( v(k,2) - v(j,2) );

    angle = atan2 ( cross, dot );

    if ( angle < 0.0 )
      value = false;
      return
    end

  end

  return
end
