function triangle_cartesian_to_barycentric_test ( )

%*****************************************************************************80
%
%% TRIANGLE_CARTESIAN_TO_BARYCENTRIC_TEST tests TRIANGLE_CARTESIAN_TO_BARYCENTRIC.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 May 2010
%
%  Author:
%
%    John Burkardt
%
  test_num = 7;

  p_test = [ ...
     0.25,   0.25; ...
     0.75,   0.25; ...
     1.00,   1.00; ...
    11.00,   0.50; ...
     0.00,   1.00; ...
     0.50, -10.00; ...
     0.60,   0.60 ]';

  a = [ 1.0, 0.0 ]';
  b = [ 4.0, 1.0 ]';
  c = [ 0.0, 3.0 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, 'TEST20655\n' );
  fprintf ( 1, '  For a triangle in 2D,\n' );
  fprintf ( 1, '  TRIANGLE_BARYCENTRIC_2D converts XY coordinates\n' );
  fprintf ( 1, '  to barycentric XSI coordinates;\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Triangle vertices:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '    A: %10f  %10f\n', a(1:2) );
  fprintf ( 1, '    B: %10f  %10f\n', b(1:2) );
  fprintf ( 1, '    C: %10f  %10f\n', c(1:2) );
  fprintf ( 1, '\n' );
  fprintf ( 1, '      Px          Py     =>   XSI(A)      XSI(B)      XSI(C) =>   Px          Py\n' );
  fprintf ( 1, '\n' );

  for test = 1 : test_num

    p(1:2,1) = p_test(1:2,test);

    xsi = triangle_cartesian_to_barycentric ( a, b, c, p );

    p2(1:2) = xsi(1) * a(1:2) + xsi(2) * b(1:2) + xsi(3) * c(1:2);

    fprintf ( 1, '  %10f  %10f  %10f  %10f  %10f  %10f  %10f\n', p(1:2), xsi(1:3), p2(1:2) );

  end

  return
end
