12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

N = 20;dt = 2*pi/N;t = 0:dt:(N-1)*dt;x = [cos(t) cos(t)];y = [sin(t) sin(t)];z = [zeros(size(t)) ones(size(t))];The matrix <strong>of</strong> vertices isvert = [x’ y’ z’];The matrix <strong>of</strong> faces must be defined so that each row gives, in order, theindices <strong>of</strong> the vertices that we want to join. The first face is formed byjoining the vertices 1,N +1,N + 2 <strong>and</strong> 2; the second face is formed byjoining the vertices 2,N +2,N + 3 <strong>and</strong> 3; <strong>and</strong> so on. The faces matrixtherefore must have the form:⎛⎞1 N +1 N +2 2⎜ 2 N +2 N +3 3 ⎟⎜⎝....N − 1 2N − 1 2N NN 2N N +1 1The faces matrix can be defined as follows:.⎟⎠faces = [1:N; N+1:2*N; [N+2:2*N N+1]; [2:N 1]]’;We now have all the data we need to draw the patch:clf1view(3)0.5h = patch(’vertices’,vert,...’faces’,faces,’facecolor’,’y’);1 010xyz0y −1 −1 xTo colour the patch, we need to specify the temperature at each <strong>of</strong> thevertices. We assume a heat source is located at (x, y, z) =(−.5, 0, 0.25),<strong>and</strong> that the temperature at any point on the cylinder is inversely proportionalto its distance away from the source. The temperature at thevertices is calculated as follows:dist = sqrt((x + 0.5).^2 + y.^2 + (z - 0.25).^2);T = 1./dist;We can now do the patch colouring:colormap(hot)set(h,’facevertexcdata’,T’,...’facecolor’,’interp’,...’edgecolor’,’none’);zc○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!