%Lecture 33: Drawing 3D-objects % sphere [x,y,z] = sphere(10); surf(x,y,z); sphere(20); % "cylinder" = rotation object cylinder(30); cylinder(30, 30); % give the curve y = y(x) x = 0:1:5 y = [1 1 2 3 2 1] plot(x,y) axis off cylinder(y, 20); cylinder([0,1,2,3,4,3,3,3,5,6], 20); % SPLINES: draw a car profile x = [1 1.8 4 4.8 6.8 7.6 8.8 9.4]; y = [1.5 2 2.1 2.5 2.5 2.2 2.0 1.5]; plot(x,y) axis off xx = 1:0.2:9.4; yy = spline(x,y,xx); size(xx) plot(x,y,'o',xx, yy) hold on % wheels t = 0:0.1:2*pi; plot(2.5+0.5*cos(t),1.5+0.5*sin(t)); plot(8.5+0.5*cos(t),1.5+0.5*sin(t)); for k = 0.1:0.05:0.9 plot(8.5+0.5*k*cos(t),1.5+0.5*k*sin(t)); end; size(t) t(63) for k = 0.1:0.05:0.9 plot(2.5+0.5*k*cos(t),1.5+0.5*k*sin(t)); end; hold off % 3D modeling: polyhedra x1 = [0 1 1]; y1 = [0 0 1]; z1 = [0 0 0]; patch(x1,y1,z1,'r') view(3),grid hold on patch([0 1 0], [0 1 1], [0 0 1], 'g') % a polyhedron v = [0 0 0 1 1 0 1 -1 0 1 0 -1 1 0 1 1 0 0 ]; f = [1 2 6 1 6 3 14 6 1 6 5]; f = [1 2 6 1 6 3 1 4 6 1 6 5]; patch('vertices', v, 'faces', f, 'facecolor', 'b') g = [2 5 6]; patch('vertices', v, 'faces', g, 'facecolor', 'r') %Hint: #5, p.5.6 x y hold off cylinder(y,20) yy cylinder(yy,20)