function t = word_to_triangle ( w, p )

%*****************************************************************************80
%
%% word_to_triangle() computes the triangle list of a polyabolo from its word.
%
%  Discussion:
%
%    The boundary word describes how to trace the boundary by starting
%    at a base point (i,j), and taking a sequence of steps of 
%    in one of 8 directions, as suggested by this diagram:
%
%      D--C--B
%   ^  |\ | /|
%   |  | \|/ |
%   J  E--P--A
%      | /|\ |
%      |/ | \|
%      F--G--H
%
%         I-->
%
%    If the current position P has coordinates (I,J), then
%    the step of given index moves to
%
%      A  (I+1,J  )
%      B  (I+1,J+1)
%      C  (I,  J+1)
%      D  (I-1,J+1)
%      E  (I-1,J  )
%      F  (I-1,J-1)
%      G  (I,  J-1)
%      H  (I+1,J-1)
%
%    The triangle list gives the IJK coordinates of triangles inside the polyabolo.
%    The (i,j) coordinates refer to a grid whose basic cell
%    is the unit square outlined by points (A,B,C,D):
%      A = (0,0) --> B = (1,0) --> C = (1,1) --> D = (0,1).
%
%      D-----C
%      |     |
%      |     |
%      |  E  |
%      |     |
%      |     |
%      A-----B
%
%    Each cell is divided into triangles with index k = 0, 1, 2, 3:
%
%      D-----C
%      |\ 2 /|
%      | \ / |
%      |3 E 1|
%      | / \ |
%      |/ 0 \|
%      A-----B
%
%    Triangles are identified by a related (i,j,k) coordinate based 
%    on the (i,j) coordinates of its vertices:
%      k = 0: A, B, E.
%      k = 1: B, C, E.
%      k = 2: C, D, E
%      k = 3: D, A, E
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 December 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string W: the boundary word.
%
%    integer P(1,2): the boundary word starting point.
%
%  Output:
%
%    integer T(TN,3): the IJK coordinates of triangles of the polyabolo.  
%
  v = word_to_vertex ( w, p );

  t = vertex_to_triangle ( v );

  return
end

