% Function to plot structural displacements

function PlotEigenmodes(self,scale,number_of_modes)

    disp([' '])
    disp(['         Plotting eigenmodes.'])

    for k = 1:number_of_modes
        
        figure
        hold on

        % Initializing deformed coordinates and displacements
        Dcoord = self.mesh.coordinates;
        Ux = zeros(size(self.mesh.coordinates,1),1);
        Uy = zeros(size(self.mesh.coordinates,1),1);

        for i = 1:size(self.mesh.coordinates,1)

            % Identifying nodal displacements
            % X axis
            Dcoord(i,1) = Dcoord(i,1)+scale*self.U(self.ID(1,i),k);
            Ux(i) = self.U(self.ID(1,i),k);
            % Y axis
            Dcoord(i,2) = Dcoord(i,2)+scale*self.U(self.ID(2,i),k);
            Uy(i) = self.U(self.ID(2,i),k);

        end

        % Displacement vector magnitude
        Gu = sqrt( Ux.^2 + Uy.^2 );

        for i = 1:size(self.mesh.incidence,1)

            inci = self.mesh.incidence;

            % Plotting displacements
            x = [ Dcoord(inci(i,2),1) Dcoord(inci(i,3),1) Dcoord(inci(i,4),1) Dcoord(inci(i,5),1) ];
            y = [ Dcoord(inci(i,2),2) Dcoord(inci(i,3),2) Dcoord(inci(i,4),2) Dcoord(inci(i,5),2) ];
            c = [ Gu(inci(i,2)) Gu(inci(i,3)) Gu(inci(i,4)) Gu(inci(i,5)) ];
            fill(x,y,c,'LineStyle','none')

        end

        axis off; axis equal;
    end

end
            