function centroids = triangle_refine_centroids ( c, t )

%*****************************************************************************80
%
%% triangle_refine_centroids() returns centroids of 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 vertices.
%
%  Output:
%
%    real centroids(N,2): the centroids.
%
  n = triangle_refine_num ( c );

  centroids = zeros ( n, 2 );

  triangle = 0;

  for i = c : -1 : 1
    for j = c - i : -1 : 0
      k = c - j - i;
      triangle = triangle + 1;
      centroids(triangle,1:2) = ( ...
        ( 3 * i - 2 ) * t(1,1:2) ...
      + ( 3 * j + 1 ) * t(2,1:2) ...
      + ( 3 * k + 1 ) * t(3,1:2) ) / 3.0 / c;
    end
  end

  for i = c : -1 : 1
    for j = c - i : -1 : 1
      k = c - j - i;
      triangle = triangle + 1;
      centroids(triangle,1:2) = ( ...
        ( 3 * i - 1 ) * t(1,1:2) ...
      + ( 3 * j - 1 ) * t(2,1:2) ...
      + ( 3 * k + 2 ) * t(3,1:2) ) / 3.0 / c;
    end
  end

  return
end
        
