function p = annulus_sample ( r1, r2, n )

%*****************************************************************************80
%
%% annulus_sample() samples a circular annulus centered at the origin.
%
%  Discussion:
%
%    A circular annulus centered at the origin, with inner radius R1 and
%    outer radius R2, is the set of points (X,Y) so that
%
%      R1^2 <= X^2 + Y^2 <= R2^2
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    04 November 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Peter Shirley,
%    Nonuniform Random Point Sets Via Warping,
%    Graphics Gems, Volume III,
%    edited by David Kirk,
%    AP Professional, 1992, 
%    ISBN: 0122861663,
%    LC: T385.G6973.
%
%  Input:
%
%    real r1, r2: the inner and outer radii.
%    0.0 <= R1, and normally R1 <= R2.
%
%    integer n: the number of points to generate.
%
%  Output:
%
%    real p(n,2): the sample points.
%
  rng ( 'shuffle' );

  if ( r1 < 0.0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'annulus_sample(): Fatal error!\n' );
    fprintf ( 1, '  Inner radius R1 < 0.0.\n' );
    error ( 'annulus_sample(): Fatal error!' );
  end

  u = rand ( n, 1 );

  theta(1:n) = u(1:n) * 2.0 * pi;

  v = rand ( n, 1 );

  r(1:n) = sqrt ( ( 1.0 - v(1:n) ) * r1 * r1 ...
       +                  v(1:n)   * r2 * r2 );

  p(1:n,1) = r(1:n) .* cos ( theta(1:n) );
  p(1:n,2) = r(1:n) .* sin ( theta(1:n) );

  return
end
