%
%   Oppgave 2b
%
figure(2), hold off
% We draw the shadow on the xy plane.
x=linspace(0,1,20); y=2-x.^2;
x=[0 x 0]; y=[0 y 0];
fill(x,y,[0.7,0.7,1]);


% First we draw the plane x=0
figure(1), hold off
s=linspace(0,1,20)';
t=s';
X=zeros(length(s),length(t));
Y=2*s*ones(size(t));
Z = s*(1-t)/2 + (9-8*s.^2)*t;
surf(X,Y,Z);
axis equal
map=colormap(gray);
colormap(0.3+0.5*map);
hold on    

% Plane y=x
X=s*ones(size(t));
Y=X;
Z=(2-s)/4*(1-t)+(9-2*s.^2)*t;
surf(X,Y,Z);
% 
% Plane 4z = 2 - 2x + y
theta = linspace(0,pi/4,20)';
r= 4./(cos(theta)+sqrt(cos(theta).^2+8*sin(theta).^2));
t=linspace(0,1,20);
X = (r.*sin(theta)) * t ;
Y = (r.*cos(theta)) * t ;
Z = 1/4*(2-2*X+Y);
surf(X,Y,Z);
% 
%  y = 2-x^2
X = s*ones(size(t));
Y = 2-X.^2;
Z=(1-s/2-s.^2/4)*(1-t)+(9-2*(2-s.^2).^2)*t;
surf(X,Y,Z);

% z = 9 - 2y^2
X = (r.*sin(theta)) * t ;
Y = (r.*cos(theta)) * t ;
Z = 9-2*Y.^2;
surf(X,Y,Z);




xlabel('x'); ylabel('y'); zlabel('z');
view(88, 78)
