function centroid = voronoi_centroids ( n, first, list_num, list, xyz, v_num, v_xyz )

%*****************************************************************************80
%
%% voronoi_centroids() computes the centroids of each polygon in a Voronoi diagram.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    02 May 2010
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of data points and Voronoi polygons.
%
%    integer FIRST(N+1), for each polygon, points to the location
%    in LIST of the index.
%
%    integer LIST_NUM, the number of items in LIST.
%
%    integer LIST(LIST_NUM), the indices of vertices that form 
%    each polygon.
%
%    real XYZ(3,N), the coodinates of the data points.
%
%    integer V_NUM, the number of Voronoi vertices.
%
%    real V_XYZ(3,V_NUM), the coordinates of the Voronoi vertices.
%
%  Output:
%
%    Output, real CENTROID(3,N), the centroid of each Voronoi polygon.
%
  centroid = zeros ( 3, n );

  r = 1.0;

  for poly = 1 : n
%
%  Compute the area of each triangle formed by one side of the polygon
%  and the Delaunay point.
%
    v3 = list(first(poly+1)-1);

    for l = first(poly) : first(poly+1) - 1

      v2 = v3;
      v3 = list(l);

      stri_area = stri_vertices_to_area ( r, ...
        xyz(1:3,poly), v_xyz(1:3,v2), v_xyz(1:3,v3) );

      stri_centroid = stri_vertices_to_centroid ( r, ...
        xyz(1:3,poly), v_xyz(1:3,v2), v_xyz(1:3,v3) );

      centroid(1:3,poly) = centroid(1:3,poly) + stri_area * stri_centroid(1:3,1);

    end

    centroid(1:3,poly) = centroid(1:3,poly) / norm ( centroid(1:3,poly) );

  end

  return
end
