function obtuse ( trial_num )

%*****************************************************************************80
%
%% obtuse() estimates the probability that a random triangle is obtuse.
%
%  Discussion:
%
%    We generate a "random" triangle as half of a rectangle whose
%    height is 1, and whose width is 1 <= L.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 January 2018
%
%  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, 'obtuse():\n' );
  fprintf ( 1, '  Define a "random" triangle as half of a rectangle\n' );
  fprintf ( 1, '  with height 1 and width 1 <= L.\n' );
  fprintf ( 1, '  What are the chances the triangle is obtuse?\n' );

  S = 0;
  L = 1;

  fprintf ( 1, '  Using value L = %g\n', L );

  for k = 1 : trial_num

    for j = 1 : 3
      r(j) = rand ( );
    end
    for j = 4 : 6
      r(j) = L * rand ( );
    end

    d1 = ( r(1) - r(2) )^2 + ( r(4) - r(5) )^2;
    d2 = ( r(2) - r(3) )^2 + ( r(5) - r(6) )^2;
    d3 = ( r(3) - r(1) )^2 + ( r(6) - r(4) )^2;

    if ( d1 < d2 + d3 & ...
         d2 < d1 + d3 & ...
         d3 < d1 + d2 )
      obtuse_triangle = 0;
    else
      obtuse_triangle = 1;
    end

    S = S + obtuse_triangle;

  end

  S = S / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated likelihoood of obtuse triangle = %g\n', S );
  fprintf ( 1, '  For L=1, expected value = %g\n', 97/150 + pi/40 );
  fprintf ( 1, '  For L=2, expected value = %g\n', 1199/1200 + 13*pi/128 - 0.75 * log(2) );

  return
end
