%***********************************************************************
%  function IntForce2DTwoNodeBar
%
%  Compute the internal force in a bar element
%***********************************************************************

function p = IntForce2DTwoNodeBar(xi, yi, xj, yj, Em, A, eftab, u)

% determine some element properties
dx = xj - xi;
dy = yj - yi;
L = sqrt( dx^2 + dy^2 );
c = dx/L;  s = dy/L;

% displacements in the element coord system
ubar = [ c s  0 0;
        -s c  0 0;
         0 0  c s;
         0 0 -s c] * [ u(eftab(1)); u(eftab(2));  u(eftab(3)); u(eftab(4)) ];
     
% deformation
e = (ubar(3) - ubar(1))/L;

% internal force
p = Em*A*e;

% Test code and output:
%
% element 3 of example truss
% p = IntForce2DTwoNodeBar(0, 0, 10, 10, 100, 2*sqrt(2), [1 2 5 6], ...
%                            [0 0 0 0 0.4 -0.2] )
%
% p =
%    2.8284

