%% Plot shapes
% Plot an imposed temperature or pressure field onto 3d solids
%
%% Function : plot_shapes
function plot_shapes()
%%
% First, supply the geometric information for the shapes you want to
% create.
R1 = 1; % Radius of the cylinder
L = 6; % Length of the cylinder
R2 = 3; % Radius of the sphere
%%
% Set up the meshes for the 3d solids. You can adjust the resolution here.
m = 100;
n = 100;
l = linspace(-L/2,L/2,m);
dl = L/m;
t = linspace(0,2*pi,n);
dt = 2*pi/n;
[lm,tm] = meshgrid(l,t);
%%
% Set up the figure window, but don't let Publish plot anything until we
% are ready.
close all;
f1 = figure(1);
set(f1,'visible','off');
%% First cylinder
% Here is the code for the first cylinder. Notice that you can adjust
% where it shows up.
xm = lm;
ym = R1*cos(tm);
zm = R1*sin(tm);
%%
% Create 'patch' handles. These are graphical objects that you can use to
% set graphical properties. Do 'get(p(1)) to see all the properties you can
% set.
p(1) = patch(surf2patch(xm,ym,zm));
set(p(1),'edgecolor','none');
set(p(1),'facecolor','interp');
%%
% Here is where the 'color' data gets set. There is one T value for each
% point on the surface of the shape.
T = temp(xm,ym,zm); % Air temperature (include your own temp or pressure field!)
set(p(1),'cdata',T);
%%
% Get ready to plot the second shape.
hold on;
%% Second cylinder
% Again, part of the goal of this project is to design your own
% configuration.
xm = R1*cos(tm);
ym = R1*sin(tm);
zm = lm;
p(2) = patch(surf2patch(xm,ym,zm));
set(p(2),'edgecolor','none');
set(p(2),'facecolor','interp');
%%
% Set temperature for each point on the shape
T = temp(xm,ym,zm); % temperature
set(p(2),'cdata',T);
%% Sphere
% Plot a sphere
xm = R2*cos(lm).*cos(tm) + 3;
ym = R2*cos(lm).*sin(tm) + 3;
zm = R2*sin(lm);
p(3) = patch(surf2patch(xm,ym,zm));
set(p(3),'edgecolor','none'); % Mesh edges
set(p(3),'facecolor','interp');
%%
% Set T value for each temperature on the shape
T = temp(xm,ym,zm);
set(p(3),'cdata',T);
%% Colormaps
% The color map used here is the 'jet' colormap. But there are lots of
% of other possibliities.
colormap(jet); % Do help 'colormap' for more possibilities
%% Set up the axis and view window
% Set up the axis
axis((L/2+2)*[ -1 1 -1 1 -1 1]);
view(3);
daspect([1 1 1]);
grid on;
colorbar;
%%
% You can also think about adding isosurfaces ('isosurf') of the background
% temperature or pressure field. Use the patch property "setfacealpha" to
% set the transparency values of the isosurfaces.
%% Lighting and material effects
% Finally, some cool lighting and material effects.
material shiny;
lighting gouraud;
camlight;
%% Final rendering
% Finally, make the figure window visible and let's see what we created.
set(f1,'visible','on');
%% function : temp(x,y,z)
% A function which can be used to color the object you are plotting.
function T = temp(xm,ym,zm)
% Do something interesting with this function.
% Mimics solution to the heat equation, assuming uniform heating on the floor.
T = -zm;
%% Download this code
%
% You can download this code here
%