function sylvester_quadrilateral ( trial_num )

%*****************************************************************************80
%
%% sylvester_quadrilateral(): probability 4 random points form concave quadrilateral.
%
%  Discussion:
%
%    The four points are chosen randomly within the unit circle.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%    
%  Input:
%
%    integer trial_num: the number of trials.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'sylvester_quadrilateral():\n' );
  fprintf ( 1, '  Estimate the probability that four points, chosen\n' );
  fprintf ( 1, '  uniformly at random in the unit circle, form a \n' );
  fprintf ( 1, '  concave (=nonconvex) quadrilateral.\n' );

  concave = 0;
  constant = 2.0 * pi;

  for k = 1 : trial_num

    for j = 1 : 4
      number1 = sqrt ( rand ( ) );
      number2 = constant * rand ( );
      X(j) = number1 * cos ( number2 );
      Y(j) = number1 * sin ( number2 );
    end

    C = convhull ( X, Y );

    if ( length ( C ) == 4 )
      concave = concave + 1;
    end
    
  end

  concave = concave / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated concave probability = %g\n', concave );
  fprintf ( 1, '  Expected value is %g.\n', 35 / 12 / pi^2 );

  return
end
