function [] = plot_teapot(data, s, t) q = size(data); p = q(1); MB = [-1 3 -3 1; 3 -6 3 0; -3 3 0 0; 1 0 0 0]; %the magic bezier matrix. %the below if's decide whether resolution information %has been given for all the patches independently or %if there is just a constant resolution. qs = size(s); qt = size(t); if qs(2) == 1 for i = 1:p/4 S(i) = s; end else S = s; end if qt(2) == 1 for i = 1:p/4 T(i) = t; end else T = t; end X = [0]; Y = [0]; Z = [0]; figure, plot3(X,Y,Z,'w'); %this bit above starts the plot so we can add to it %with the line function. %for each patch... for k = 1:4:p CX = data(k:k+3,[1 4 7 10]); CY = data(k:k+3,[2 5 8 11]); CZ = data(k:k+3,[3 6 9 12]); %clear the line segments in case the resolution %has changed. clear('X','Y','Z'); %for each s, for all t along that s, add some more %line. for i = 0:S((k+3)/4) for j = 1:T((k+3)/4)+1 res = bez(CX,MB,i/S((k+3)/4),(j-1)/T((k+3)/4)); X(j) = res(1); vs(1) = res(2); vt(1) = res(3); res = bez(CY,MB,i/S((k+3)/4),(j-1)/T((k+3)/4)); Y(j) = res(1); vs(2) = res(2); vt(2) = res(3); res = bez(CZ,MB,i/S((k+3)/4),(j-1)/T((k+3)/4)); Z(j) = res(1); vs(3) = res(2); vt(3) = res(3); cr = cross(vs,vt); if norm(cr) ~= 0 cr = cr/norm(cr); end %draws the normal. line([X(j) X(j)+3*cr(1)], [Y(j) Y(j)+3*cr(2)], [Z(j) Z(j)+3*cr(3)],'Color',[.1 0 1]); end %draws the line segments for this s. line(X,Y,Z,'Color',[0 0 0]); end %as above, except now for each t, for all s along that t, %add some more line and draw. Notice that we need not %redraw the normals, since the points are the same. In %fact, with some additional data structure, this second %nested for loop would be unecessary. for j = 0:T((k+3)/4) for i = 1:S((k+3)/4)+1 res = bez(CX,MB,(i-1)/S((k+3)/4),j/T((k+3)/4)); X(i) = res(1); vs(1) = res(2); vt(1) = res(3); res = bez(CY,MB,(i-1)/S((k+3)/4),j/T((k+3)/4)); Y(i) = res(1); vs(2) = res(2); vt(2) = res(3); res = bez(CZ,MB,(i-1)/S((k+3)/4),j/T((k+3)/4)); Z(i) = res(1); vs(3) = res(2); vt(3) = res(3); end line(X,Y,Z,'Color',[0 0 0]); end end