function [ w2, p2_ij ] = t_rotate_word ( w, p_ij, r )

%*****************************************************************************80
%
%% t_rotate_word() returns the boundary word for a rotated object.
%
%  Discussion:
%
%    The rotation is done about the base point, that is, the vertex of
%    triangle #1 associated with the 30 degree angle.
%
%      D--C--B  B--A--H
%   ^  |\ | /|  |\ | /|
%   |  | \|/ |  | \|/ |
%   J  E--P--A  C--P--G
%      | /|\ |  | /|\ |
%      |/ | \|  |/ | \|
%      F--G--H  D--E--F
%
%         I-->
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 January 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    character vector W: the boundary word.
%
%    integer P_IJ(1,2): the (i,j) coordinates of the base point.
%
%    integer R: indicates the number of 90 degree rotations, which should 
%    be 0, 1, 2, or 3.
%
%  Output:
%
%    character vector W2: the boundary word of the rotated object.
%
%    integer P2_IJ(1,2): the (I,J) coordinates of the base point
%    of the rotated object.
%
  p2_ij(1,1:2) = p_ij(1,1:2);
%
%  Decrease each character by 2 * R positions, wrapping around at the end.
%
  wn = length ( w );
  w2 = '';

  r = i4_wrap ( r, 0, 3 );

  for wi = 1 : wn
    c = w(wi);
    cr = c - 2 * r;
    if ( 'A' <= c & c <= 'H' )
      ci = ch_wrap ( cr, 'A', 'H' );
    elseif ( 'a' <= c & c <= 'h' )
      ci = ch_wrap ( cr, 'a', 'h' );
    else
      ci = '?';
    end
    w2 = [ w2, ci ];
  end
  
  return
end

