
function [f, tau] = springLoads(q,Q,xi,xstar,K,length)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Computes components (f,tau) of net force and torque
% of a Hookean spring attached to a rigid body with 
% configuration (q,Q).  The spring parameters are
%
%       K      = stiffness
%       length = relaxed length
%       xi     = body point (d-frame)
%       xstar  = anchor point (e-frame)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x = q + Q*xi  ;            %position of attachment (e frame)
eta = xstar - x ;          %vector along spring (e frame)
normeta = sqrt(eta'*eta) ; %current length of spring

f = K*(normeta-length)*eta/normeta ; %spring force (e frame)
tau = Q'*( crossmat(x-q)*f ) ;       %spring torque (d frame)

