function triangle_xy_to_xsi_test ( )

%*****************************************************************************80
%
%% triangle_xy_to_xsi_test() tests triangle_xy_to_xsi().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2023
%
%  Author:
%
%    John Burkardt
%
  t = [ ...
     4.0, 2.0; ...
     1.0, 5.0; ...
    -2.0, 2.0 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'triangle_xy_to_xsi_test():\n' );
  fprintf ( 1, '  triangle_xy_to_xsi() converts XY to XSI coordinates.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  We verify that (X,Y) -> (XSI1,XSI2,XSI3) -> (X,Y)\n' );
  fprintf ( 1, '  works properly.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Triangle vertices:\n' );
  disp ( t );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Sample points:\n' );
  fprintf ( 1, '\n' );

  for k = 1 : 10

    p = zeros ( 1, 2 );

    if ( k == 1 )
      for j = 1 : 2
        p(j) = sum ( t(1:3,j) ) / 3.0;
      end
    elseif ( k == 2 )
      p(1,1) = 3.0;
      p(1,2) = 0.0;
    else
      p = triangle_sample ( t, 1 );
    end

    xsi = triangle_xy_to_xsi ( t, p );

    p2 = triangle_xsi_to_xy ( t, xsi );

    fprintf ( 1, '\n' );
    fprintf ( 1, '  %8f  %8f    %8f  %8f  %8f\n', p, xsi );
    fprintf ( 1, '  %8f  %8f\n', p2 );

  end

  return
end
