function bary = triangle_cartesian_to_barycentric ( t, p )

%*****************************************************************************80
%
%% triangle_cartesian_to_barycentric() converts Cartesian to barycentric coordinates.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 July 2023
%
%  Author:
%
%    John Burkardt
%
  bary = zeros ( 1, 3 );

  a = t(1,1:2);
  b = t(2,1:2);
  c = t(3,1:2);

  bcp = line_parameter_t ( b, c, p );
  cap = line_parameter_t ( c, a, p );
  abp = line_parameter_t ( a, b, p );

  bca = line_parameter_t ( b, c, a );
  cab = line_parameter_t ( c, a, b );
  abc = line_parameter_t ( a, b, c );

  bary = [ bcp / bca, cap / cab, abp / abc ]; 

  return
end
