% Use % % help plot3 % % to get some documentation on plotting. % % The command % % plot3(x,y,z) % % draws a polygon through the points % (x(1),y(1),z(1)) ,..., (x(n),y(n),z(n)), % where x,y,z are column vectors of length n. % % To get a cube, imagine tracing the edges in sequence % and then put the vertex coordinates into x,y, and z % in the order they are encountered. It is OK to retrace edges. % % The following solution with n=16 retraces 3 edges: % Vertices in the order they are encountered: u = [ 0 0 0; 1 0 0; 1 0 1; 1 1 1; 1 1 0; 0 1 0; 0 1 1; 0 0 1; 0 0 0; 0 1 0; 0 1 1; 1 1 1; 1 1 0; 1 0 0; 1 0 1; 0 0 1; 0 0 0] % Copy columns into x,y,z and plot: x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) % Clear the current figure clf % Save the original cube u0=u % Make a rotation matrix and turn the cube c=cos(0.1); s=sin(0.1); R=[c s 0; -s c 0; 0 0 1]; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) % Set the axes big enough to see the cube in context: lims = [-2 2]; axis([lims lims lims]); axis manual; hold on u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z) u=u*R; x=u(:,1); y=u(:,2); z=u(:,3); plot3(x,y,z)