%**************************************************************************
%This function calculates the fields BX and BY in the X, Y coordinate system
%after fields bx and by in the x, y coordinate system are rotated by a given angle.
%
%Method:
%Let X, Y be the coordinate system of the undulator.  Rotate the magnet by
%angle theta.  The coordinate system the magnet was measured in is also
%rotated by theta.  We want the field in the undulator coordinate system
%given the field in the measured magnet system.
%bx = B . ex
%by = B . ey
%BX = B . EX
%   = (B . ex ex + B . ey ey) . EX
%   = bx (ex . EX) + by (ey . EX)
%   = bx cos(th) + by (-sin(th))
%BY = B . EY
%   = (B . ex ex + B . ey ey) . EY
%   = bx (ex . EY) + by (ey . EY)
%   = bx sin(th) + by cos(th)
%
%Input:
%bx, x-component of the field in the x, y system (T)
%by, y-component of the field in the x, y system (T)
%th, angle about the zZ-axis to rotate the x, y system and the bx and by fields (rad)
%
%Output:
%BX, X-component of the field after rotation (T)
%BY, Y-component of the field after rotation (T)
%
%Zachary Wolf, 4/30/13

function [BX, BY] = sup_calc_rot_fields(bx, by, th)

%Calculate BX and BY
BX = bx * cos(th) - by * sin(th);
BY = bx * sin(th) + by * cos(th);

%Done
end
