clear; clc; close all;

%% 3D lines
% plot3
% x = [1 2 5];
% y = [2 3 4];
% z = [1 3 0];

t = linspace(0, 6*pi, 30);
 x = 3*cos(t);
 y = 1*sin(t);
 z = 0.01*t.^2;

figure;
hold on;
plot3(x,y,z);
plot3(x,y,z, 'mo');
xlabel('x')
ylabel('y')
zlabel('z')
grid on;
axis('equal')

%% 3D surfaces
%  patch
x = [1 2 5];
y = [2 3 4];
z = [1 3 0];

figure
patch(x, y, z, 'm');
grid on;

% mesh
% x1 = [-1 1];
% x2 = [-2 -0.1 1.7];
x1 = linspace(-pi, pi, 20);
x2 = linspace(-10, 16, 30);

%  call meshgrid to create a cartesian product of x1, x2
[X1, X2] = meshgrid(x1, x2);

% Evaluate the function at these (X1, X2) pairs
Z = cos(X1).*X2;
mesh(X1, X2, Z);
grid on;
xlabel("x_1")
ylabel("x_2")
zlabel('z = f(x_1, x_2)')
title('Using the ''mesh'' function')
view([35 30])

% surf
figure
surf(X1, X2, Z);
grid on;
xlabel("x_1")
ylabel("x_2")
zlabel('z = f(x_1, x_2)')
title('Using the ''surf'' function')
view([35 30])
% get rid of black lines in the surface plot
shading interp   
colormap(jet(50))
colorbar   % adds a colorbar that acts as a legend for colors

% contour
figure
% contour(X1, X2, Z);
contourf(X1, X2, Z);
grid on;
xlabel("x_1")
ylabel("x_2")
zlabel('z = f(x_1, x_2)')
title('Using the ''contour'' function')

% surfc
figure
surfc(X1, X2, Z);
grid on;
xlabel("x_1")
ylabel("x_2")
zlabel('z = f(x_1, x_2)')
title('Using the ''surf'' function')
view([35 30])
% get rid of black lines in the surface plot
shading interp   
colormap(jet(50))
colorbar   % adds a colorbar that acts as a legend for colors

% Make a composite plot
x1_line = linspace(-1,1, 20);
x2_line = linspace(0,10,20);
z_line = cos(x1_line).*x2_line;

figure
hold on;
surfc(X1, X2, Z);
plot3(x1_line, x2_line, z_line, 'm', 'LineWidth',2);
grid on;
xlabel("x_1")
ylabel("x_2")
zlabel('z = f(x_1, x_2)')
title('A composite plot')
view([35 30])
% get rid of black lines in the surface plot
shading interp   
colormap(jet(50))
colorbar   % adds a colorbar that acts as a legend for colors

% Generate the Matlab logo
figure;
L = 160*membrane(1, 100);
surf(L)
shading interp
colormap autumn


