clear all; close all;
source = 'hw9prob2data';

fid = fopen(source,'r');
A = fread(fid,[1 inf],'char');
fclose(fid);

A = reshape(A,[512 512]);
[X Y] = meshgrid(linspace(-1,1,512));

subplot(121);
surf(X,Y,A);
shading interp;
view([0 90]);
xlabel('X (normalized)');
ylabel('Y (normalized)');
colormap('bone');
title(source);

s = linspace(-1,1); % Integration direction
P = zeros(512,180); % Projections
subplot(122);
for i = 1:180
    % Resample image with the projection axis laid out horizontally
    X2 = X*cosd(i) + -Y*sind(i);
    Y2 = X*sind(i) + Y*cosd(i);
    A2 = interp2(X,Y,A,X2,Y2,'linear',0);
    surf(X,Y,A2);
    shading interp;
    view([0 90]);
    drawnow;
    P(:,i) = sum(A2)';
end