function R = computeRotationMatrix(element_data)
    if strcmp(element_data{1}, '2dTruss')
        coordinates_element = [element_data{3}; element_data{4}];
        R = computeRotationMatrix_2dTruss(coordinates_element);
        
    elseif strcmp(element_data{1}, '2dElasticBeam')
        coordinates_element = [element_data{3}; element_data{4}];
        R = computeRotationMatrix_2dBeam(coordinates_element);
        
    elseif strcmp(element_data{1}, 'spring')
        R = 1;  % Assuming this represents an identity or no rotation case
    end
end


function R = computeRotationMatrix_2dTruss(coordinates_element)
    % Computes the rotation matrix for a 2D truss element

    theta = atan2(coordinates_element(2,2) - coordinates_element(1,2), coordinates_element(2,1) - coordinates_element(1,1));

    C = cos(theta);
    S = sin(theta);

    R = [ C,  S, 0, 0;
         -S,  C, 0, 0;
          0,  0, C, S;
          0,  0, -S, C];
end


function R = computeRotationMatrix_2dBeam(coordinates_element)
    % Computes the rotation matrix for a 2D beam element

    theta = atan2(coordinates_element(2,2) - coordinates_element(1,2), coordinates_element(2,1) - coordinates_element(1,1));

    C = cos(theta);
    S = sin(theta);

    R = [ C,  S, 0, 0, 0, 0;
         -S,  C, 0, 0, 0, 0;
          0,  0, 1, 0, 0, 0;
          0,  0, 0, C,  S, 0;
          0,  0, 0, -S, C, 0;
          0,  0, 0, 0,  0, 1];
end
