function wireplot(v,e) % % DESCRIPTION: % Makes a wire plot of the polyhedron defined by vertices % in the rows of v and edges in the rows of e. % The plot is in the default 3-D view, % without axis labeling, tick marks and background. % % REQUIRED: % size(v,2) = 3, i.e.: v has three columns; % size(e,2) = 2, i.e.: e has two columns; and % all elements in e are in the range 1:size(v,1). % % EXAMPLE: % v = [0 0 0; 2 0 0; 1 2 0; 1 1 1]; % e = [1 2; 2 3; 3 1; 1 4; 2 4; 3 4]; % wireplot(v,e) % shows a tetrahedron % axis off hold on for i=1:size(e,1) x = [v(e(i,1),:); v(e(i,2),:)]; plot3(x(:,1),x(:,2),x(:,3)); end; view(3) hold off function tv = translate(v,t) % % DESCRIPTION: % Translates the vertices in v by adding the vector t % to every vector in v. % % REQUIRED: % size(t,2) = size(v,2), i.e.: t and v have same #columns % tv = v; for i=1:size(v,1) tv(i,:) = v(i,:) + t; end; function tv = transform(v,t) % % DESCRIPTION: % Transforms the vertices in v, multiplying every row in v % by the matrix t. % % REQUIRED: % size(t,1) = size(t,2) = size(v,2) = 3, % i.e.: t is 3-by-3 matrix and v has three columns. % tv = v; for i=1:size(v,1) x = v(i,:); y = t*x'; tv(i,:) = y'; end; function b = barycenter(v) % % DESCRIPTION: % Computer the barycenter of the vertices in the rows of v. % b = [0 0 0]; for i=1:size(v,1) b = v(i,:) + b; end; b = b/size(v,1); function tv = scale(v,f) % % DESCRIPTION: % Scales the polyhedron spanned by the vertices in the rows % of v by a (positive) factor f. % b = barycenter(v); tv = translate(v,-b); s = diag([f f f]); tv = transform(tv,s); tv = translate(tv,b); v = [0 0 0; 1 0 0; 0 1 0; 1 1 0; 0 0 1; 1 0 1; 0 1 1; 1 1 1]; e = [1 2; 1 3; 2 4; 3 4; 5 6; 5 7; 6 8; 7 8; 1 5; 2 6; 3 7; 4 8]; figure; i = 2*pi/30; a = 0; r = 10; f = 1; for k = 1:100 a = a + i; t = [r*cos(a),r*sin(a),k*10]; u = translate(v,t); u = scale(u,f); wireplot(u,e); r = 0.99*r; f = 0.99*f; end; diary off