function [ x, y ] = hexagon01_sample ( n )

%*****************************************************************************80
%
%% hexagon01_sample samples uniformly from the regular unit hexagon.
%
%  Discussion:
%
%    The unit hexagon has center (0,0) and "radius" 1.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    19 April 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of points.
%
%  Output:
%
%    real X(N), Y(N), the points.
%
  rng ( 'shuffle' );
%
%  Set basis vectors for each rhombus.
%
  v = [ ...
    -1.0, 0.5,            0.5,           -1.0; ...
     0.0, sqrt(3.0)/2.0, -sqrt(3.0)/2.0,  0.0 ];
%
%  Assign each point randomly to one of the rhombuses.
%
  rh = randi ( [ 1, 3 ], n, 1 );

  i = find ( rh == 1 );
  j = find ( rh == 2 );
  k = find ( rh == 3 );
%
%  Set barycentric coordinates of each point in its rhombus.
%
  xy = rand ( 2, n );
%
%  Convert to physical coordinates.
%
  x = zeros ( n, 1 );
  x(i) = v(1,1:2) * xy(1:2,i);
  x(j) = v(1,2:3) * xy(1:2,j);
  x(k) = v(1,3:4) * xy(1:2,k);

  y = zeros ( n, 1 );
  y(i) = v(2,1:2) * xy(1:2,i);
  y(j) = v(2,2:3) * xy(1:2,j);
  y(k) = v(2,3:4) * xy(1:2,k);

  return
end
