You could use constraint equations. I don't quite know the answer but here's an approach similar to what bonded contact uses but without coupling rotation:
Start with the nonlinear constraint that the initial distance between the nodes is equal to the deformed distance (|A| = |B| in the picture). Then write that equation in terms of node coordinates (constants, points 1 and 2 in the picture) and displacements (variables, vectors u1 and u2 in the picture) which leads to, I think, one big quadratic equation. Then drop the quadratic terms (because small displacements) and you're left with a linear equation.
That's a very general solution and quite labour intensive because you have to recalculate the constants in the constraint equations if you change the node coordinates. Maybe you can make it simpler depending on your situation.
Comments
Start with the nonlinear constraint that the initial distance between the nodes is equal to the deformed distance (|A| = |B| in the picture). Then write that equation in terms of node coordinates (constants, points 1 and 2 in the picture) and displacements (variables, vectors u1 and u2 in the picture) which leads to, I think, one big quadratic equation. Then drop the quadratic terms (because small displacements) and you're left with a linear equation.
That's a very general solution and quite labour intensive because you have to recalculate the constants in the constraint equations if you change the node coordinates. Maybe you can make it simpler depending on your situation.