%**************************************************************************
%This function calculates the slippage distance between the light and the
%electrons in an undulator.
%
%Input:
%gamma, electron beam Lorentz factor
%z, position along the undulator (m)
%x_p, slope of the beam x trajectory at z (dimensionless)
%y_p, slope of the beam y trajectory at z (dimensionless)
%
%Output:
%slip, the distance between the light and the electrons at z (m)
%
%Zachary Wolf, 6/30/10

%Calculations:
%Electron speed along z axis:
%gamma = 1 / sqrt(1 - v^2/c^2)
%v^2 = c^2 (1 - 1/gamma^2)
%v^2 = vz^2 + vx^2 + vy^2 = vz^2 (1 + x'^2 + y'^2)
%vz^2 = v^2 / (1 + x'^2 + y'^2)
%vz^2 = c^2 (1 - 1/gamma^2) / (1 + x'^2 + y'^2)
%vz = c sqrt( (1 - 1/gamma^2) / (1 + x'^2 + y'^2) )
%
%Slippage, distance between electrons and light:
%d_slip = (c - vz) d_t
%d_slip = (c - vz) (dz / vz)
%d_slip = ((c / vz) - 1) dz
%slip = int ((c / vz) - 1) dz
%slip(z = 0) = 0

function slip = slip_calc_slip_slope(gamma, z, x_p, y_p)

%Calculate (vz/c)^2
%vz^2 = c^2 (1 - 1/gamma^2) / (1 + x'^2 + y'^2)
%(vz/c)^2 = (1 - 1/gamma^2) / (1 + x'^2 + y'^2)
vz_c_sq = (1 - 1 / gamma^2) ./ (1 + x_p.^2 + y_p.^2);

%Calculate vz/c
vz_c = sqrt(vz_c_sq);

%Calculate c/vz
c_vz = 1 ./ vz_c;

%Calculate the slippage
%slip = int ((c / vz) - 1) dz
slip = int_calc_int_y_dx(z, c_vz - 1);

%Done
