function [ distanceToTravel ] = FindTravelDistance( r1, r2, uMax, v, dt, thetaf)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
    if uMax == 0;
        R = 100000;
    else
        R = 1/uMax;
    end
    dTheta = uMax*v*dt;
    
    r2Prime = r2 + R*tan(dTheta/2);
    r1Prime = r1 - R*tan(dTheta/2);
    r3 = sqrt((r1Prime*r1Prime)+(r2Prime*r2Prime)-2*r1Prime*r2Prime*cos(dTheta)); %law of cosines
    phi = pi - asin(r1Prime*sin(dTheta)/r3) - dTheta; %phi is original angle of incidence with barrier
    thetaOfTurning = pi - phi;
    r1h = r1 - R*tan(thetaOfTurning/2);
	h = r1h*cos(phi-pi/2);
    
    thetafPrime = thetaOfTurning - thetaf;
    distanceToTravel = (h/tan(thetafPrime)) - R*tan(thetafPrime/2);
end



