function [ mu, var ] = triangle_distance_stats ( v, n )

%*****************************************************************************80
%
%% triangle estimates distance statistics for a given triangle.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    20 February 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real V(3,2), the vertices of the triangle.
%
%    Input, integer N, the number of sample points to use.
%
%    Output, real MU, VAR, the estimated mean and variance of the
%    distance between two random points in the triangle.
%
  p = triangle_sample ( v, n );
  q = triangle_sample ( v, n );

  t = ( p - q ) .^ 2;
  t = sum ( t, 2 );
  t = sqrt ( t );
  mu = sum ( t ) / n;

  if ( 1 < n )
    var = sum ( ( t(1:n) - mu ) .^ 2 ) / ( n - 1 );
  else
    var = 0.0;
  end

  return
end
