function prob = inside ( )

%*****************************************************************************80
%
%% inside() analyzes the origin in the random triangle in the circle problem.
%
%  Discussion:
%
%    Pick three points on the unit circle and create a triangle.
%    What is the probability that the origin is inside the triangle?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
% 
%  Modified:
%
%    08 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  Output:
%
%    real prob, the probability that the origin is inside the triangle.
%
  total = 0;
%
%  We are free to designate the first "random" point as (1,0).
%
  x1 = 1.0;
  y1 = 0.0;

  trial_num = 100000;

  for loop = 1 : trial_num

    alpha = 2.0 * pi * rand ( );
    x2 = cos ( alpha );
    y2 = sin ( alpha );

    beta = 2.0 * pi * rand ( );
    x3 = cos ( beta );
    y3 = sin ( beta );
%
%  Line from P1 to P2, compare P3 and Z.
%
    m = ( y2 - y1 ) / ( x2 - x1 );
    b = y1 - m * x1;
    check1 = y3 - ( m * x3 + b );
    check2 = -b;
%
%  Line from P2 to P3, compare P1 and Z.
%
    m = ( y3 - y2 ) / ( x3 - x2 );
    b = y2 - m * x2;
    check5 = y1 - ( m * x1 + b );
    check6 = -b;
%
%  Line from P3 to P1, compare P2 and Z.
%
    m = ( y1 - y3 ) / ( x1 - x3 );
    b = y3 - m * x3;
    check3 = y2 - ( m * x2 + b );
    check4 = -b;

    p1 = check1 * check2;
    p2 = check3 * check4;
    p3 = check5 * check6;

    if ( 0.0 < p1 && 0.0 < p2 && 0.0 < p3 )
      total = total + 1;
    end
    
  end

  prob = total / trial_num;

  return
end
