% 1. the basics: spheres and cylinders [x,y,z] = sphere(10); % samples the unit sphere size(x) ans = 11 11 surf(x,y,z) % render the sphere % sphere does the sampling for us automatically [x,y,z]=cylinder(30); figure surf(x,y,z) hold on surf(z,y,x) % on the plot we see two cylinders of height one, % and radius 30, the first one was about the z-axis, % the second one about the x-axis figure cylinder([1 0]) % the arguments of cylinder are the distance of % the z-axis to the walls of the cylinder hold on cylinder([0 1]) % alternatively, we may first sample [x,y,z] = cylinder([0 1]); % and then render surf(x,y,z); t = 0:0.01:1; r = t.^2; cylinder(r) s = t.^(1/2); hold on cylinder(s) % 2. Cubic Splines x = [1.0 1.8 4.0 4.8 6.8 7.6 8.8 9.4]; y = [1.5 2.0 2.1 2.5 2.5 2.2 2.0 1.5]; figure plot(x,y) axis([0 10 0 4]); % this model defines the shape of a car % splines are used to smoothen the shape % We will first sample the shape xx = 1:0.2:9.4; yy = spline(x,y,xx); hold on plot(x,y,'o',xx,yy); figure subplot(2,1,1); plot(x,y); axis([0 10 0 4]); subplot(2,1,2); plot(x,y,'o',xx,yy); axis([0 10 0 4]); hold on t = 0:0.01:2*pi; plot(2.5 + 0.5*cos(t),1.5 + 0.5*sin(t)); for k = 0.1:0.05:0.8 plot(2.5 + 0.5*k*cos(t),1.5 + 0.5*k*sin(t)); end; % It is recommended that a script is made, % to avoid unnecessary typing. % 3. Polytopes and Polyhedral models x1 = [0 1 1]; y1 = [0 0 1]; z1 = [0 0 0]; figure patch(x1,y1,z1,'r'); x2 = [0 1 0]; y2 = [0 1 1]; z2 = [0 0 1]; hold on patch(x2,y2,z2,'g'); view(3), grid % a more complicated polyhedral model % is defined by vertices and faces: v = [0 0 0; 1 1 0; 1 -1 0; 1 0 -1; 1 0 1; 1 0 0]; % vertices f = [1 2 6; 1 6 3; 1 4 6; 1 5 6]; % faces figure patch('vertices',v,'faces',f,'facecolor','g'); view(3),grid diary off