%**************************************************************************
%This function calculates the trajectory from the velocity of a particle in
%the undulator.
%
%Input:
%z, z position along the undulator (m)
%vx, x component of the velocity (m/s)
%vy, y component of the velocity (m/s)
%vz, z component of the velocity (m/s)
%
%Output:
%x, x trajectory (m)
%y, y trajectory (m)
%x_p, x', dx/dz (dimensionless)
%y_p, y', dy/dz (dimensionless)
%
%Zachary Wolf, 6/22/10

function [x, y, x_p, y_p] = traj_calc_traj(z, vx, vy, vz)

%Method
%Once vx, vy, and vz are known,
%vx = dx/dt = dx/dz dz/dt = vz x'
%x' = vx/vz, y' = vy/vz
%x = int(vx/vz)dz, y = int(vy/vz)dz
  
%Check
if (length(z) ~= length(vx)) || (length(z) ~= length(vy)) || (length(z) ~= length(vz))
    msgbox('traj_calc_traj_from_vel: arrays have different lengths', 'Error');
    return;
end
if length(z) < 10
    msgbox('traj_calc_traj_from_vel: problem with array sizes', 'Error');
    return;
end

%Calculate the slopes dx/dz and dy/dz
x_p = vx ./ vz;
y_p = vy ./ vz;

%Integrate the slopes to get the positions
x = int_calc_int_y_dx(z, x_p);
y = int_calc_int_y_dx(z, y_p);
    
%Done
