function centroid = triangle_centroid ( t )

%*****************************************************************************80
%
%% triangle_centroid() computes the centroid of a triangle in 2D.
%
%  Discussion:
%
%    The centroid of a triangle can also be considered the
%    center of gravity, or center of mass, assuming that the triangle
%    is made of a thin uniform sheet of massy material.
%
%    The centroid of a triangle is the intersection of the medians.
%
%    A median of a triangle is a line connecting a vertex to the
%    midpoint of the opposite side.
%
%    In barycentric coordinates, in which the vertices of the triangle
%    have the coordinates (1,0,0), (0,1,0) and (0,0,1), the centroid
%    has coordinates (1/3,1/3,1/3).
%
%    In geometry, the centroid of a triangle is often symbolized by "G".
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2023
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Adrian Bowyer and John Woodwark,
%    A Programmer's Geometry,
%    Butterworths, 1983.
%
%  Input:
%
%    real T(3,2), the triangle vertices.
%
%  Output:
%
%    real CENTROID(1,2), the coordinates of the centroid.
%
  centroid = zeros (1,2);

  for j = 1 : 2
    centroid(j) = sum ( t(1:3,j) ) / 3.0;
  end

  return
end
