function ij = ijk_to_ij ( ijk )

%*****************************************************************************80
%
%% ijk_to_ij() is given an IJK triangle, returns the (i,j) coordinates of vertices.
%
%  Discussion:
%
%    The (i,j) coordinates refer to a parallelogram whose basic cell
%    is the unit parallelogram outlined by points (A,B,C,D)
%    with (i,j) coordinates
%      A = (0,0) --> B = (1,0) --> C = (1,1) --> D = (0,1).
%
%         D-----C
%        /     /
%       /     /
%      A-----B
%
%    Each cell is divided into k=0 and k=1 triangles:
%
%         *-----*
%        / \ 1 /
%       / 0 \ /
%      *-----*
%
%    Triangles are identified by a related (i,j,k) coordinate based 
%    on the (i,j) coordinates of its vertices:
%      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:
%
%    16 October 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer IJK(3), the IJK parallelogram coordinates of a triangle.
%
%  Output:
%
%    real IJ(3,2): the IJ parallelogram coordinates of the vertices.
%
  ij = zeros ( 3, 2 );

  i = ijk(1);
  j = ijk(2);
  k = ijk(3);

  if ( k == 0 )
    ij = [ ...
      i - 1, j - 1; ...
      i,     j - 1; ...
      i - 1, j ];
  elseif ( k == 1 )
    ij = [ ...
      i,     j; ...
      i - 1, j; ...
      i,     j - 1 ];
  else
    fprintf ( 1, '\n' );
    fprintf ( 1, 'ijk_to_ij - Fatal error!' );
    fprintf ( 1, '  Triangle has illegal value k = %d\n', k );
    error ( 'ijk_to_ij - Fatal error!' );
  end

  return
end

