%**************************************************************************
%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, 3/30/04, 12/26/05

%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) ~= c^2 (1 - 1/gamma^2) (1 - x'^2 - y'^2)
%vz^2 ~= c^2 (1 - 1/gamma^2 - x'^2 - y'^2)
%vz ~= c (1 - (1/2) (1/gamma^2) - (1/2) x'^2 - (1/2) y'^2)
%
%Slippage, distance between electrons and light:
%d_slip = (c - vz) d_t = (1 - vz/c) d_z
%d_slip = ((1/2) (1/gamma^2) + (1/2) x'^2 + (1/2) y'^2) d_z
%slip = (1/2) int (1/gamma^2 + x'^2 + y'^2) d_z

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

%Calculate the slippage
slip = (1 / 2) *  int_calc_int(z, (1. / gamma^2) + x_p.^2 + y_p.^2);

%Done
