function c = centroids( nodes, tricellvxs, triangles )
%c = centroids( nodes, tricellvxs, triangles )
%   Find the centroids of the triangles.

    if nargin < 3
        c = permute( sum( reshape( nodes( tricellvxs', : ), 3, [], 3 ), 1 ), [2 3 1] );
    else
        c = permute( sum( reshape( nodes( tricellvxs(triangles,:)', : ), 3, [], 3 ), 1 ), [2 3 1] );
    end
end
