function [ x, y ] = triangle_ijk_to_xy ( i, j, k )

%*****************************************************************************80
%
%% triangle_ijk_to_xy returns the Cartesian coordinates of an IJK triangle.
%
%  Discussion:
%
%    If k = 0, the "ijk" triangle has vertices
%      (i-1,j-1), (i,j-1), (i-1,j).
%    If k = 1, the "ijk" triangle has vertices
%      (i,j), (i-1,j), (i,j-1).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 August 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I, J, K, the indices of the triangle.
%
%  Output:
%
%    integer X(3), Y(3): the Cartesian coordinates of the vertices.
%
  x = zeros ( 3, 1 );
  y = zeros ( 3, 1 );

  if ( k == 0 )
    x(1) = i - 1 + ( j - 1 ) / 2;
    x(2) = i     + ( j - 1 ) / 2;
    x(3) = i - 1 +   j       / 2;
    y(1) = ( j - 1 ) * sin ( pi / 3.0 );
    y(2) = ( j - 1 ) * sin ( pi / 3.0 );
    y(3) =   j       * sin ( pi / 3.0 );
  elseif ( k == 1 )
    x(1) = i     +   j       / 2;
    x(2) = i - 1 +   j       / 2;
    x(3) = i     + ( j - 1 ) / 2;
    y(1) =   j       * sin ( pi / 3.0 );
    y(2) =   j       * sin ( pi / 3.0 );
    y(3) = ( j - 1 ) * sin ( pi / 3.0 );
  else
    fprintf ( 1, '\n' );
    fprintf ( 1, 'triangle_ijk_to_xy - Fatal error!\n' );
    fprintf ( 1, '  Triangle has illegal k index = %d.\n', k );
    error ( 'triangle_ijk_to_xy - Fatal error!' );
  end

  return
end
