function polygon_average_test ( )

%*****************************************************************************80
%
%% polygon_average_test tests polygon_average.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    25 February 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../polygon_average' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_average_test\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Test polygon_average\n' );
  fprintf ( 1, '  Repeatedly average the vertices of a polygon.\n' );
%
%  Define the starting polygon.
%
  n = 10;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of vertices will be %d\n', n );

  p = 2.0 * rand ( n, 2 ) - 1;

  figure ( 1 )
  clf
  plot ( [ p(1:n,1); p(1,1) ], [ p(1:n,2); p(1,2) ], 'Color', 'b', 'Marker', 'o' );
  grid on
  axis ( [ -1.0, +1.0, -1.0, +1.0 ] )
  axis equal
  title ( 'Original polygon', 'Fontsize', 24 );

  filename = 'polygon_original.png';
  print ( '-dpng', filename );
%
%  Repeatedly average the vertices.
%
  for step = 1 : 20

    figure ( 2 )
    clf
    grid on
    axis ( [ -1.0, +1.0, -1.0, +1.0 ] )
    axis equal
    hold on
    plot ( [ p(1:n,1); p(1,1) ], [ p(1:n,2); p(1,2) ], 'Color', 'b', 'Marker', 'o' );
    p2 = polygon_average ( n, p );
    plot ( [ p2(1:n,1); p2(1,1) ], [ p2(1:n,2); p2(1,2) ], 'Color', 'r', 'Marker', 'o', 'LineWidth', 3 );
    string = sprintf ( 'After averaging step %d\n', step );
    title ( string, 'Fontsize', 24 );
    hold off

    p = p2;
%
%  Wait one second.
%
    pause ( 1.0 );

  end

  filename = 'polygon_average.png';
  print ( '-dpng', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_average_test\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../polygon_average' );

  return
end
