function triangle_refine_plot ( c, t, filename )

%*****************************************************************************80
%
%% triangle_refine_plot() plots a refined triangle().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 March 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer C: the number of refinements.
%
%    real T(3,2): the triangle vertices.
%
%    string filename: the name of the file into which graphics will be saved.
%
  centroids = triangle_refine_centroids ( c, t );

  clf ( );
  hold ( 'on' )
    for s = 0 : c
      x1 = ( s * t(1,1) + ( c - s ) * t(3,1) ) / c;
      x2 = ( s * t(2,1) + ( c - s ) * t(3,1) ) / c;
      y1 = ( s * t(1,2) + ( c - s ) * t(3,2) ) / c;
      y2 = ( s * t(2,2) + ( c - s ) * t(3,2) ) / c;
      plot ( [ x1, x2 ],  [ y1, y2 ], 'b-' );
    end
    for s = 0 : c
      x1 = ( s * t(1,1) + ( c - s ) * t(2,1) ) / c;
      x2 = ( s * t(3,1) + ( c - s ) * t(2,1) ) / c;
      y1 = ( s * t(1,2) + ( c - s ) * t(2,2) ) / c;
      y2 = ( s * t(3,2) + ( c - s ) * t(2,2) ) / c;
      plot ( [ x1, x2 ],  [ y1, y2 ], 'b-' );
    end
    for s = 0 : c
      x1 = ( s * t(2,1) + ( c - s ) * t(1,1) ) / c;
      x2 = ( s * t(3,1) + ( c - s ) * t(1,1) ) / c;
      y1 = ( s * t(2,2) + ( c - s ) * t(1,2) ) / c;
      y2 = ( s * t(3,2) + ( c - s ) * t(1,2) ) / c;
      plot ( [ x1, x2 ],  [ y1, y2 ], 'b-' );
    end
    plot ( [ t(:,1); t(1,1) ],  [ t(:,2); t(1,2) ], 'r-', 'linewidth', 3 );
    plot ( centroids(:,1), centroids(:,2), 'k.', 'markersize', 15 );
  hold ( 'off' )
  grid ( 'on' );
  axis ( 'equal' );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

