


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Computer Graphics3D Affine transforms
Introduction to Transformations n Introduce 3D affine transformation: n Position (translation) n n Size (scaling)Orientation (rotation) n Previously developed 2D (x,y)^ n^ Shapes (shear) n n Now, extend to 3DExtend transform matrices to 3D or (x,y,z) case n Enable transformation of points by multiplication
Transforms in 3D n n 2D:3D: 3x3 matrix multiplication4x4 matrix multiplication: homogenous coordinates n n Recall: transform object = transform each verticeGeneral form:
031 032 033 134
21 22 23 24
11 12 13 14 m m m m
m m m m
m m m m M
1 1^ z
y
x z
y
x P
P
P QQ M Xform of P Q
Recall: 3x3 2D Translation Matrix
x y^ ' ' ^ =^ x y + tt yx
y
x
= (^) *
ßPreviously, 2D :
2D Scaling ßScale: Alter object size by scaling factor (sx, sy). i.e
x’ = x. Sxy’ = y. Sy
(1,1)
(2,2) Sx = 2, Sy = 2 (2,2)
(4,4)
yx '' = Sx 0 Sy^0 yx
Recall: 3x3 2D Scaling Matrix
xy '' = Sx 0 Sy^0 yx
y
x Sy
Sx y
x
Example: OpenGL Table Leg // define table leg//-------------------------------------------------------------------------- void tableLeg(double thick, double len){------ glPushMatrix();glTranslated(0, len/2, 0); glScaled(thick, len, thick);glutSolidCube(1.0); } glPopMatrix();
Recall: 3x3 2D Rotation Matrix
(x,y)
(x’,y’) θ r φ
yx '' = ^ cos(sin( θθ )) −cos(sin( θθ )) yx
sin( ) cos( ) 0
cos( ) sin( ) 0 1
y
x y
x θ θ
θ θ
Rotating in 3D n New terminology n X-roll: rotation about x-axis n n Y-roll: rotation about y-axisZ-roll: rotation about z-axis n Which way is +ve rotation n Look in –ve direction (into +ve arrow) n CCW is +ve rotation
x
y z+
Rotating in 3D
Rotating in 3D
= − 0 0 0 1
0 0
0 1 0 0
0 0 s c
c s Ry β
A y-roll:
0 0 0 1
0 0 1 0
0 0
0 0 s c
c s Rz β
A z-roll:
Rules:•Rotate row, column int. is 1•Rest of row/col is 0 •c,s in rect pattern
OpenGL: glrotated( θ, 0,1,0 )
OpenGL: glrotated( θ, 0,0,1 )
Example: Rotating in 3D
= − 1
1
1
4
1
3
0 0 0 1
0 0
0 1 0 0
0 0 s c
c s Q
Q: Using y-roll equation, rotate P = (3,1,4) by 30 degrees: A: c = cos(30) = 0.866, s = sin(30) = 0.5, and
E.g. first line: 3.c + 1.0 + 4.s + 1.0 = 4.
Matrix Multiplication Code n Outline of solution: n Declare P,Q as array: n Declare transform matrix as 2-dimensional array^ • Double P[4], Q[4]; n Remember: C indexes from 0, not 1^ • Double M[4][4]; n Long way: • Write out equations line by line expression for Q[i]
Matrix Multiplication Code n Using loops looks like: n for(i=0;i<4;i++) {temp = 0; for(j=0;j<4;j++){ } temp += P[j]*M[i][j]; }Q[i] = temp; n n Test matrice code rigorouslyUse known results (or by hand) and plug into your code