function [] = plotResult( impath, springLength, maxDeflectionAngle, maxDeflectionLocation, springDeflection, avgPitch, maxPitch, maxPitchLocation, pitchStdDeviation, midpointMatrix, edgeMidpointMatrix, distanceMatrix, connectionMatrix, centers )
%PLOTRESULT Summary of this function goes here
%   Plots a summary of the given spring

figure; imshow(impath); hold on;

% Number of vertices
vertices = size(distanceMatrix, 1);
segments = size(midpointMatrix, 1);

for i = 1:vertices 
    for j = 1:vertices 
        if (connectionMatrix(i,j) > 0)
            plot([centers(i, 1) centers(j, 1)], [centers(i, 2) centers(j, 2)], 'r', 'LineWidth', 1.5);
        end
    end
end

plot(maxPitchLocation(:, 1), maxPitchLocation(:, 2), 'g--', 'LineWidth', 1.5);
plot(maxPitchLocation(:, 1), maxPitchLocation(:, 2), 'r*', 'MarkerSize', 10);

for i = 1:vertices 
    if (sum(connectionMatrix(i, :) > 0) >= 1)
        plot(centers(i,1),centers(i,2), 'r.');
    end
    
    if (sum(edgeMidpointMatrix(i, :) > 0) == 2)
        plot([edgeMidpointMatrix(i,1) centers(i,1)], [edgeMidpointMatrix(i,2) centers(i,2)], 'color', [1 .4 0], 'LineWidth', 1.15);
    end
end

for i = 2:segments
    if (sum(midpointMatrix(i-1, :) > 0) == 2 && sum(midpointMatrix(i, :) > 0) == 2)
        plot([midpointMatrix(i-1, 1) midpointMatrix(i, 1)], [midpointMatrix(i-1, 2) midpointMatrix(i, 2)], 'b', 'LineWidth', .75);
    end
end

plot(midpointMatrix(:,1),midpointMatrix(:,2),'b.');
plot(maxDeflectionLocation(1), maxDeflectionLocation(2), 'r*', 'MarkerSize', 10);
text(maxDeflectionLocation(1) + 10, maxDeflectionLocation(2),'\leftarrow Biggest deflection',...
     'BackgroundColor', [0.97 0.96 0.86],...
     'FontSize', 8,...
     'FontName', 'Arial',...
     'LineStyle', '-',...
     'EdgeColor', [0 0 0],...
     'LineWidth', 0.1)

if (maxPitchLocation(1, 2) < maxPitchLocation(2, 2))
    text(maxPitchLocation(1, 1) + 7.5, maxPitchLocation(1, 2) + 18.5, '\leftarrow Biggest pitch',...
         'BackgroundColor', [0.97 0.96 0.86],...
         'FontSize', 8,...
         'FontName', 'Arial',...
         'LineStyle', '-',...
         'EdgeColor', [0 0 0],...
         'LineWidth', 0.1)
else
    text(maxPitchLocation(2, 1) + 7.5, maxPitchLocation(2, 2) + 18.5, '\leftarrow Biggest pitch',...
         'BackgroundColor', [0.97 0.96 0.86],...
         'FontSize', 8,...
         'FontName', 'Arial',...
         'LineStyle', '-',...
         'EdgeColor', [0 0 0],...
         'LineWidth', 0.1)
end

figure; hold on;
set(gca, 'visible', 'off');

str = cell(0,1);
str = [str; 'Total length of the spring:              ' num2str(springLength) ' mm     '];
str = [str; 'Biggest deflection angle:                ' num2str(maxDeflectionAngle) '° '];
str = [str; 'Total spring deflection:                  ' num2str(springDeflection) '°  '];
str = [str; 'Average pitch length:                    ' num2str(avgPitch) '  mm        '];
str = [str; 'Biggest pitch length:                     ' num2str(maxPitch) ' mm        '];
str = [str; 'Std. deviation of pitch lengths:      ' num2str(pitchStdDeviation) ' mm   '];

text(.06, .55, str, ...
     'BackgroundColor', [0.97 0.96 0.86],...
     'FontSize', 12,...
     'FontName', 'Arial',...
     'LineStyle', '-',...
     'EdgeColor', [0 0 0],...
     'LineWidth', 0.1)
 
result = 'The spring is';
color = 'r';
if (abs(springDeflection) > 1.6 && ((maxPitch-avgPitch) > 0.6 || pitchStdDeviation > 0.3))
    result = [result ' bent and stretched.'];
    color = 'r';
elseif (abs(springDeflection) > 1.6 && (maxPitch-avgPitch) <= 0.6 && pitchStdDeviation <= 0.3)
    result = [result ' bent, but regular.'];
    color = 'r';
elseif (abs(springDeflection) <= 1.6 && ((maxPitch-avgPitch) > 0.6 || pitchStdDeviation > 0.3))
    result = [result ' straight, but stretched.'];
    color = 'r';
elseif (abs(springDeflection) <= 1.6 && (maxPitch-avgPitch) <= 0.6 && pitchStdDeviation <= 0.3)
    result = [result ' straight and regular.'];
    color = 'g';
end

text(.06, .3, result, ...
     'color', color, ...
     'BackgroundColor', [0.97 0.96 0.86],...
     'FontSize', 12,...
     'FontName', 'Arial',...
     'LineStyle', '-',...
     'EdgeColor', [0 0 0],...
     'LineWidth', 0.1)

end