function viewStruct(S, Shat)

F = size(S,1)/3;
% x1 = min(min(S(1:3:end, :)));
% y1 = min(min(S(2:3:end, :)));
% z1 = min(min(S(3:3:end, :)));
% x2 = max(max(S(1:3:end, :)));
% y2 = max(max(S(2:3:end, :)));
% z2 = max(max(S(3:3:end, :)));

s = mean(std(S, 1, 2));
S = S/s;
sm = mean(S,2);
S = S - sm*ones(1,size(S,2));

Shat = Shat/s;

Y = findRotation(S, Shat);         % Procrust Alignment
for i=1: F
    Shat(3*i-2:3*i,:) = Y*Shat(3*i-2:3*i,:);
end;

for i=1: F
    plot3(S(3*i-2, :), S(3*i-1, :), S(3*i, :), 'b.');
    if exist('Shat')
        hold on
        plot3(Shat(3*i-2, :), Shat(3*i-1, :), Shat(3*i, :), 'rO');
        hold off
    end
    axis tight vis3d equal

    view(179.5, -85)
    %         view(104.5, 14)
    %         view(2.5, 36)
    title(i);
    grid on

    pause(0.1)
end;