Sweep - Translational and Rotational
Sweep - Translational and Rotational
Sweep - Translational and Rotational
Sweep representations
Define shape Define sweep path
Sweep representations
Sweep representations
Define sweep path
Sweep representations
Define shape
Source: http://groups.csail.mit.edu/graphics/classes/6.837/F98/talecture/
18/01/2012
Basic transformations
Translation (shift) Scaling
Rotation
Translation
Scaling
about the origin
D
D Y A B D C B T = [Tx Ty Tz] A C
A
Y
x = x + Tx y = y + Ty z = z + Tz
D A B C B
S = [Sx Sy Sz]
Z X
Y Positive angle of rotation is counter-clockwise when the axis about which it occurs points toward the observer
18/01/2012
A
Z A D
B
C X
A A Z B
B C X
Positive angle
Positive angle
Rotation
Direction of positive rotation is from Y to Z
X
B C A
C A B
Z
Positive angle
from X to Y
Matrix representation
Homogeneous coordinates
Common notation for ALL transformations Common computational mechanism for ALL transformations Simple mechanism for combining a number of transformations => computational efficiency
Homogeneous coordinates
Point P = (x, y, z ) represented by a vector
x y = [x y z 1]T z 1 Transformations
P=
M=
a b c 0
d e f 0
g h i 0
j k l 1
18/01/2012
d e f 0
g h i 0
j k l 1
x y z 1
Translation, scaling, rotation and perspective projection, all defined through matrices
Translation
x = x + Tx y = y + Ty z = z + Tz x = Sx * x y = Sy * y z = Sz * z
Scaling
T=
1 0 0 0
0 1 0 0
0 Tx 0 Ty 1 Tz 0 1
Sx 0 S= 0 0
0 Sy 0 0
0 0 Sz 0
0 0 0 1
0 0 1 0
0 0 0 1
0 0 0 1
18/01/2012
cos Ry = 0 -sin 0
0 sin 0 1 0 0 0 cos 0 0 0 1
% Define a crossection of a unit cube in the YZ plane crossection=[0 0 0 1 01 01 01 11 0 0 1 1]; K=4; % Define a sweep path (relative displacement vectors) path=[0 0 0 100 2 0 0]; % Create a vertex table for n=1:N Tm=makehgtform('translate',path(:,n)); i1=K*(n-1)+1; % current start index to array V i2=K*(n-1)+K; % current end index to array V V(:,i1:i2)=Tm*C; end
% Generate vertex table for all the side-faces for n=1:K:K*(N-1) for k=1:K F((n-1)+k,1)=(n-1)+k; F((n-1)+k,2)=n+K+k-1; F((n-1)+k,3)=n+K+k; F((n-1)+k,4)=(n-1)+k+1; F((n-1)+k,5)=F((n-1)+k,1); end end % ... And for the end faces for k=1:K EndFaces(1,:)=[1:K]; EndFaces(2,:)=[K*N:-1:K*(N-1)+1]; end
Rotational sweep
Define a shape as a polygon vertex table
-200
- 10
10
20
-100
100
Define a sweep path as a sequence of rotations Rotate the shape, continue building a vertex table Define a surface table
18/01/2012
%% Generate a crossection in 3D (homogeneous coords) % Simple circle equation for k=1:K C(k,1)=rK*cosd((k-1)*alphaK); C(k,2)=rK*sind((k-1)*alphaK); C(k,3)=0; C(k,4)=1; end
20 15 10 5 0 -5 -10 -15 -20 -20 - 10 0
% Generate vertices % Rotate the crossection about % axis Y for n=K:K:K*N V(:,n+1:n+K)=Ry* V(:,1:K);
10 20
end
%% Generate torus % Define 3D transformation matrices Tm=makehgtform('translate',[rN 0 0]); % Translation Ry=makehgtform('yrotate',alphaN*pi/180); % Rotation about Y axis % Translate the crossection Ctemp (only once) V(:,1:K)=Tm*C;
% Generate face table (pointers to vertices, not vertices themselves) for n=1:K:K*N for k=1:K F((n-1)+k,1)=(n-1)+k; F((n-1)+k,2)=(n-1)+k+1; F((n-1)+k,3)= n+K+k; F((n-1)+k,4)= n+K+k-1; end end
-200
-100
100
Homework
1. Suggest a simple way of applying a transformation defined by a matrix M to a large set of N 3-dimensional vertices in homogeneous coordinates. 2. Explain how you would define a surface table for a sphere using a sweep function. Specify precisely the shape and the sweep path. 3. For adventureous: Using a sweep function define an egg shape (NOT an ellipsoid!)
Matlab exercise
Extend the code in ex2_torus.m to define and display five linked toruses in different colours. You will also need file torus.m which is a function generating the face and the vertex table for a torus. Matlab code for both functions is in file www.cs.bham.ac.uk/~exc/Teaching/Graphics/ex2_torus.zip Write Matlab code to generate a surface table for a sphere using a sweep function.
Next lecture