function square_distance_pdf ( )

%*****************************************************************************80
%
%% SQUARE_DISTANCE_PDF plots the PDF for the square distance problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    25 December 2018
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Eric Weisstein,
%    "Square Line Picking." 
%    From MathWorld--A Wolfram Web Resource.,
%    http://mathworld.wolfram.com/SquareLinePicking.html
%
  d = linspace ( 0.0, sqrt ( 2.0 ), 101 );

  pdf = 2 * d .* ( d.^2 - 4 * d + pi ) .* ( d <= 1.0 ) ...
      + 2 * d .* (4 .* sqrt ( d.^2 - 1 ) - ( d.^2 + 2 - pi ) ...
      - 4.0 * atan ( sqrt ( d.^2 - 1 ) ) ) .* ( 1.0 < d );

  plot ( d, pdf, 'r-', 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- Distance -->' );
  ylabel ( '<-- Probability -->' );
  title ( 'PDF for distance between pairs of random points in unit square' );

  return
end

