function obtuse1 ( trial_num )

%*****************************************************************************80
%
%% obtuse1(): probability that three points in [0,1] define an obtuse triangle.
%
%  Discussion:
%
%    We generate a "random" triangle by choosing two random values to
%    break the unit interval into three pieces.  We ask for the probability
%    that the resulting triangle is obtuse.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 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, 'obtuse1():\n' );
  fprintf ( 1, '  Define a "random" triangle by splitting the unit\n' );
  fprintf ( 1, '  interval into three random pieces.\n' );
  fprintf ( 1, '  What are the chances the triangle is obtuse?\n' );

  S = 0;

  for k = 1 : trial_num

    point1 = rand ( );
    point2 = rand ( );
    if ( point1 > point2 )
      temp = point1;
      point1 = point2;
      point2 = temp;
    end

    a = point1;
    b = point2 - point1;
    c = 1.0 - point2;

    if ( a + b > c & a + c > b & b + c > a )
      d1 = a^2;
      d2 = b^2;
      d3 = c^2;
      if ( d1 < d2 + d3 & d2 < d1 + d3 & d3 < d1 + d2 )
        obtuse_triangle = 0;
      else
        obtuse_triangle = 1;
      end
      S = S + obtuse_triangle;
    end

  end

  S = S / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated likelihoood of obtuse triangle = %g\n', S );
  fprintf ( 1, '  Exact value is %g\n', 9/4 - 3.0 * log(2) );

  return
end
