%% Lab 11 and 12 


clc; % clearing the command window
clear; % clearing all variables
close all; % closing all open plots

%% 15-15
load wind; % loading the file containing data form  MATLAB library

% Defining the limit variables
[x,y,z,v] = flow;
xmin = min(x(:));
ymin = min(y(:));
zmin = min(z(:));
xmax = max(x(:));
ymax = max(y(:));
zmax = max(z(:));

% Plotting a slice plane
hslice = surf(linspace(xmin,xmax,100),linspace(ymin,ymax,100),zeros(100));

% Rotating the plane
rotate(hslice,[-1,0,0],-45)

% Saving the data
xd = get(hslice,'XData');
yd = get(hslice,'YData');
zd = get(hslice,'ZData');
delete(hslice) % deleting the plot

% Now plotting new plot based on data from deleted plot
figure(1)
h = slice(x,y,z,v,xd,yd,zd);
set(h,'FaceColor','interp','EdgeColor','none','DiffuseStrength',.8)

% Plot properties
hold on
hx = slice(x,y,z,v,xmax,[],[]);
set(hx,'FaceColor','interp','EdgeColor','none')
hy = slice(x,y,z,v,[],ymax,[]);
set(hy,'FaceColor','interp','EdgeColor','none')
hz = slice(x,y,z,v,[],[],zmin);
set(hz,'FaceColor','interp','EdgeColor','none')
daspect([1,1,1])
axis tight
box on
view(-38.5,16)
camzoom(1.4)
camproj perspective
lightangle(-45,45)
colormap (jet(24))
set(gcf,'Renderer','zbuffer')
colormap (flipud(jet(24)))
caxis([-5,2.4832])
colorbar('horiz')

%% 15-20

% Using rand to generate random data for plot
data = rand(12,12,12);
data = smooth3(data,'box',5);
isoval = .5;

% Plotting isosurface for use data for isonormal plot
figure(2)
h = patch(isosurface(data,isoval),'FaceColor','blue','EdgeColor','none','AmbientStrength',.2,'SpecularStrength',.7,'DiffuseStrength',.4);

% Plotting the isonormals
isonormals(data,h)

% Plot properties
patch(isocaps(data,isoval),'FaceColor','interp','EdgeColor','none')
colormap hsv
daspect([1,1,1])
axis tight
view(3)
camlight right
camlight left
set(gcf,'Renderer','zbuffer');
lighting phong

%% 15-32

load wind % loading input data file
% Defining the limits for the plot
xmin = min(x(:));
xmax = max(x(:));
ymax = max(y(:));
zmin = min(z(:));

% calculating the wind speed 
wind_speed = sqrt(u.^2 + v.^2 + w.^2);

% Plotting slice planes 
figure(3)
hsurfaces = slice(x,y,z,wind_speed,[xmin,100,xmax],ymax,zmin);
set(hsurfaces,'FaceColor','interp','EdgeColor','none')

hcont = contourslice(x,y,z,wind_speed,[xmin,100,xmax],ymax,zmin);
set(hcont,'EdgeColor',[.7,.7,.7],'LineWidth',.5)
[sx,sy,sz] = meshgrid(80,20:10:50,0:5:15); % mesh grid for data to be plotted
hlines = streamline(x,y,z,u,v,w,sx,sy,sz); % plotting stream lines

% Plot properties
set(hlines,'LineWidth',2,'Color','r')
view(3)
daspect([2,2,1])
axis tight

%% 15-42

load wind % loading iput data
wind_speed = sqrt(u.^2 + v.^2 + w.^2); % calculating wind speed

% Plotting isosurface
figure(4)
hiso = patch(isosurface(x,y,z,wind_speed,40)); % data for plot
isonormals(x,y,z,wind_speed,hiso) % plot command

% Plot properties
set(hiso,'FaceColor','red','EdgeColor','none');hcap = patch(isocaps(x,y,z,wind_speed,40),'FaceColor','interp','EdgeColor','none');
colormap hsv
daspect([1,1,1]);
[f , verts] = reducepatch(isosurface(x,y,z,wind_speed,30),0.07);

% Plotting the first set of cones
h1 = coneplot(x,y,z,u,v,w,verts(:,1),verts(:,2),verts(:,3),3);
set(h1,'FaceColor','blue','EdgeColor','none');

xrange = linspace(min(x(:)),max(x(:)),10);
yrange = linspace(min(y(:)),max(y(:)),10);
zrange = 3:4:15;
[cx,cy,cz] = meshgrid(xrange,yrange,zrange); % mesh grid for plotting

% Plotting the second set of cones
h2 = coneplot(x,y,z,u,v,w,cx,cy,cz,2); 
set(h2,'FaceColor','green','EdgeColor','none');

% Plot properties
axis tight
box on
camproj perspective
camzoom(1.25)
view(65,45)
camlight(-45,45)
set(gcf,'Renderer','zbuffer');
lighting phong
set(hcap,'AmbientStrength',.6)





