function [ w2, p2_xy ] = word_rotate_xy ( w, p_xy, r )

%*****************************************************************************80
%
%% word_rotate_xy() returns the boundary word for a rotated object.
%
%  Discussion:
%
%    The boundary word describes how to trace the boundary of a shape
%    by starting at a base point P and taking a sequence of 
%    steps of varying length in one of 12 directions, as suggested by 
%    this diagram:
%
%      +....+....D....+....+
%      .    E         C    .
%      . F               B .
%      .                   .
%      G         P         A
%      .                   .
%      . H               L .
%      .    I         K    .
%      +....+....J....+....+
%
%    The boundary word specifies a base point P, and then a sequence of
%    directions along which steps are taken.  Because of the geometry,
%    the length of a step varies with the direction and sequence, being 
%    either always 1/2, or else, in measures of 4, 
%    sqrt(3)/3, sqrt(3)/6, sqrt(3)/6, sqrt(3)/3.
%
%    Symbol  Direction  Stepsize
%   
%    A       E          1/2
%    B,b     ENE        sqrt(3)/3, sqrt(3)/6
%    C       NNE        1/2
%    D,d     N          sqrt(3)/3, sqrt(3)/6
%    E       NNW        1/2
%    F,f     WNW        sqrt(3)/3, sqrt(3)/6
%    G       W          1/2
%    H,h     WSW        sqrt(3)/3, sqrt(3)/6
%    I       SSW        1/2
%    J,j     S          sqrt(3)/3, sqrt(3)/6
%    K       SSE        1/2
%    L,l     ESE        sqrt(3)/3, sqrt(3)/6
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 November 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    character vector W: the boundary word.
%
%    integer P_XY(1,2): the (x,y) coordinates of the base point.
%
%    integer R: indicates the number of 60 degree rotations, which should 
%    be 0, 1, 2, 3, 4, or 5.
%
%  Output:
%
%    character vector W2: the boundary word of the rotated object.
%
%    integer P2_XY(1,2): the (x,y) coordinates of the base point
%    of the rotated object.
%
  p2_xy(1,1:2) = p_xy(1,1:2);
%
%  Advance each character by 2*R positions, wrapping around at the end.
%
  wn = length ( w );
  w2 = '';

  r = i4_wrap ( r, 0, 5 );

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

