function F = CableConnection(body1,bodies,n,name,p_a1,p_a2,Spring_Force_Coeffs,Damping_Force_Coeffs)

j = 0;
for i = 1:length(bodies)
name2 = get(bodies{i},'name');
  if(strcmp(name2,name))
    j = i;
  end
end
if(j == 0)
   error('ERROR: Can not find name match in CableConnection');
end

body2 = bodies{j};

dt = get(body1,'dt');

disp(['Computing Forces on ',get(body1,'name'),' due to ',get(body2,'name')]);

sv1 = get(body1,'sv');
sv2 = get(body2,'sv');

xo1 = get(body1,'x0');
xo2 = get(body2,'x0');
pos1 = sv1(1:6);
vel1 = sv1(7:12);
pos2 = sv2(1:6);
vel2 = sv2(7:12);


if(strcmp(get(body1,'name'),'Winch'))  %Body 1 is winch, modify p_a1 to account for winch pay-out/pay-in
pos1
pos1(3) = pos1(3)+.45*pos1(5);   
else    %Body 2 is winch modify pos2 to account for winch pay-out/pay-in
pos2
pos2(3) = pos2(3)+.45*pos2(5);
end


[Elongation,ElongationRate,s] = TetherElongations(xo1,pos1,vel1,p_a1,xo2,pos2,vel2,p_a2);
Elongation
s


F = zeros(1,6);

if(Elongation > 0)
  SpringTension = ppval(Spring_Force_Coeffs,Elongation);
  F(1) = SpringTension*s(1);
  F(3) = SpringTension*s(3);

  %DampingTension = ppval(Damping_Force_Coeffs,ElongationRate);

  %F(1) = F(1) + DampingTension*s(1);
  %F(3) = F(3) + DampingTension*s(3);
end


R = eye(3);
if(~strcmp(get(body1,'name'),'Winch'))  %Don't need this rotation for winch because the attachement point doesn't move with rotation of winch.
  R(1,1) = cos(pos1(5)); R(1,3) = sin(pos1(5));  
  R(3,1) = -R(1,3);  R(3,3) = R(1,1);
end
p_size = size(p_a1);
if(p_size(2) > p_size(1)) 
    p_a1 = p_a1'; 
end
M  = cross(R*p_a1,F(1:3));

F(5) = M(2);
F

end





