function [curvature] = UkSA( k, n, coords, barrier, targetx, targety, w)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
    gamma = 30;
    
    
    xk = coords(k, 1);
    yk = coords(k, 2);
    thetak = coords(k, 3);
    curvature = 0;
    
    bsize = size(barrier);
    blength = bsize(1);
    
    xsum = 0;
    ysum = 0;
    numberseen = 0;
    minbdist = w;
    for i = 1:blength
        x2 = barrier(i, 1);
        y2 = barrier(i, 2);
        bdistance = sqrt((x2-xk)^2 + (y2-yk)^2);
        if bdistance < minbdist
            minbdist = bdistance;
        end
        xsum = xsum + x2*C(bdistance, 0, w);
        ysum = ysum + y2*C(bdistance, 0, w);
        numberseen = numberseen + C(bdistance, 0, w);
    end
    
    if numberseen == 0
        nu = 0;
    else
        xaverage = xsum/numberseen;
        yaverage = ysum/numberseen;
        
        thetab = atan((yaverage-yk)/(xaverage-xk)) - thetak;
        if (xaverage - xk) < 0
            thetab = thetab + pi;
        end
        thetab = mod(thetab, 2*pi);
        
        if thetab < pi/2
            m = -1;
        elseif thetab < 3*pi/2
            m = 0;
        else
            m = 1;
        end
        nu = m*cos(thetab);
    end  
    curvature = curvature + (gamma)*nu/w;
    
    for i = 1:n
       if i == k
       else
%            xj = coords(i, 1);
%            yj = coords(i, 2);
           curvature = curvature + (gamma/4)*Ujk(i, k, coords);
%            rlength = sqrt((xj-xk)^2 + (yj-yk)^2);
%            if numberseen == 0
%                curvature = curvature + 10*Ujk(i, k, coords);
%            else
%                curvature = curvature + C(rlength, 0, w)*UjkSeek(xj, yj, xk, yk, thetak);
%            end
           
       end
    end
    curvature = curvature + gamma*UjkSeek(targetx, targety, xk, yk, thetak);
end

%     
%     
%     nu = 0;
%     for i = 1:blength
%         x1 = coords(k, 1);
%         y1 = coords(k, 2);
%         theta1 = coords(k, 3);
%         
%         x2 = barrier(i, 1);
%         y2 = barrier(i, 2);
%         
%         blength = sqrt((x2-x1)^2 + (y2-y1)^2);
%         thetab = atan((y2-y1)/(x2-x1)) - theta1;
%         if (x2 - x1) < 0
%             thetab = thetab + pi;
%         end
%         thetab = mod(thetab, 2*pi);
%         
%         if thetab < pi/2
%             m = -1;
%         elseif thetab < 3*pi/2
%             m = 0;
%         else
%             m = 1;
%         end
%         nu = nu + 2*m*cos(thetab)*C(blength, 0, w);
%     end
%     
%     curvature = curvature + nu;


