function [QGlobal_elem, KMaterialGlobal_elem, KGeomGlobal_elem, QLocal_elem]=elemStateDetermin(elemIdx,elem,numEquations, v)
dofs_elem = numEquations{elemIdx};

T = computeRotationMatrix(elem);
u = T * v(dofs_elem);

if strcmp(elem{1}, '2dElasticBeam')
    [qBar, KBar] = elemStateDetermin_2dElasticBeam(elem, u);

    l = norm(elem{4} - elem{3});
    [LTransfo, Kgeom] = computeTransfoBasicToLocal(elem{8}, l, u, qBar);

    QLocal_elem = LTransfo' * qBar;
    QGlobal_elem = T' * QLocal_elem;
    KMaterialGlobal_elem = T' * (LTransfo' * KBar * LTransfo) * T;
    KGeomGlobal_elem = T' * Kgeom * T;
end
end


function [qBar, KBar]=elemStateDetermin_2dElasticBeam(elem,u)
l = norm(elem{4} - elem{3});
E = elem{5};
A = elem{6};
I = elem{7};

KBar = [
    E * A / l,           0,                0;
    0,           4 * E * I / l,     2 * E * I / l;
    0,           2 * E * I / l,     4 * E * I / l
];

uBar = computeUbar(elem{8}, l, u);

qBar = KBar * uBar;
end