%**************************************************************************
%This function calculates the position of a charge in global coordinates
%after a rotation and translation from its position in block coordinates.
%
%Input:
%pos_block, position of charge [x, y, z] in block coordinates, origin is block center (m)
%rot, rotation matrix, rotate the block about its center, direction cosines R_ij = e_rot_i . e_orig_j
%trans, translate the rotated block in x, y, and z in global coordinates parallel to the original block coordinates [t_x, t_y, t_z] (m)
%
%Output:
%pos, position of charge [x, y, z] in global coordinates (m)
%
%Zachary Wolf, 4/8/10

function [pos] = pm_charge_calc_rot_trans_pos(pos_block, rot, trans)

%Rotate the charge about the block center
%Global coordinates stay parallel to original block coordinates
%Use active interpretation and rotate block coordinates and block
%r_g = x_g_i e_g_i, fixed global coordinates, e_i = unit vector in i-direction
%r_b = x_b_i e_b_i, rotated block coordinates, x_i's don't change in rotation
%e_b_i = e_b_i . e_g_j e_g_j
%      = R_ij e_g_j
%r_b = x_b_i e_b_i
%    = x_b_i R_ij e_g_j
%Therefore, after the rotation, the block coordinates are
%x_g_j = x_b_i R_ij
pos_rot = pos_block * rot;

%Translate the center of the rotated block to the desired position in global coordinates
pos = pos_rot + trans;

%Done