CS 4731: Computer Graphics Lecture 8: 3D Affine Transforms: Emmanuel Agu
CS 4731: Computer Graphics Lecture 8: 3D Affine Transforms: Emmanuel Agu
Emmanuel Agu
Introduction to Transformations
x Px
y or Py
z P
Pz
1
1
3D Coordinate Systems
All perpendicular: X x Y = Z ; Y x Z = X; Z x X
= Y;
Tip: sweep fingers x-y: thumb is z y
Y
+z
x x
+z
Previously, 2D :
x' x tx
y' y t
y
x' 1 0 tx x
y' 0 1 ty * y
1 0 0 1 1
3x3 2D Translation Matrix
Now, 3D : x' x tx
y' y ty
z' z t
OpenGL: z
gltranslated(tx,ty,tz)
x' 1 0 0 tx x
y' 0 1 0 ty y
z' 0 * z
0 1 tz
1
1 0 0 0 1
Where: x= x.1 + y.0 + z.0 + tx.1 = x + tx, etc
2D Scaling
x = x . Sx x' Sx 0 x
y = y . Sy y ' 0 Sy y
(4,4
)
(2,2) Sx = 2, Sy = 2
(2,2)
(1,1)
3x3 2D Scaling Matrix
x' Sx 0 x
y ' 0 Sy y
x' Sx 0 0 x
y ' 0 Sy 0 y
1 0 0 1 1
4x4 3D Scaling Matrix
x' Sx 0 0 x
Example:
y ' 0 Sy 0 y If Sx = Sy = Sz = 0.5
1 0 0 1 1
Can scale:
big cube (sides = 1) to
small cube ( sides = 0.5)
2D: square, 3D cube
x' Sx 0 0 0 x
y' 0 Sy 0 0 y
z' 0 0 Sz 0
z OpenGL:
1 0 0 0 1 1 glScaled(Sx,Sy,Sz)
Rotation
(x, y) (x,y)
r
How to compute (x, y) ?
x = r cos () y = r sin ()
x = r cos ( +) y = r sin ( +)
Rotation
Matrix form?
3 x 3?
3x3 2D Rotation Matrix
New terminology
X-roll: rotation about x-axis
Y-roll: rotation about y-axis
Z-roll: rotation about z-axis
Which way is +ve rotation
Look in ve direction (into +ve arrow)
CCW is +ve rotation
+ x
z
Rotating in 3D
Rotating in 3D
c cos s sin
A x-roll:
1 0 0 0
0 c s 0
Rx
0
OpenGL:
0 s c
glrotated(, 1,0,0)
0 0 0 1
Rotating in 3D
A y-roll: c 0 s 0
Rules:
0 1 0 0
Ry
Rotate row, column
OpenGL:
0
int. is 1
s 0 c
glrotated(, 0,1,0) Rest of row/col is 0
0 0 0 1
c,s in rect pattern
A z-roll:
c s 0 0
s c 0 0
Rz
OpenGL: 0 0 1 0
glrotated(, 0,0,1) 0 0 0 1
Rotating in 3D
c 0 s 0 3 4.6
0 1 0 0 1 1
Q
s 0 c 0 4 1.964
0 0 0 1 1 1
where
Outline of solution:
Declare P,Q as array:
Double P[4], Q[4];
Declare transform matrix as 2-dimensional array
Double M[4][4];
Remember: C indexes from 0, not 1
Long way:
Write out equations line by line expression for Q[i]
E.g. Q[0] = P[0]*M[0][0] + P[1]*M[0][1] + P[2]*M[0][2] +
P[3]*M[0][3]
Cute way:
Use indexing, say i for outer loop, j for inner loop
Rotating in 3D
z
3D Rotation About Arbitrary Axis
M Rz ( 3 ) R y ( 2 ) Rx ( 1 )
3D Rotation About Arbitrary Axis
Ru ( ) R y ( ) Rz ( ) Rx ( ) Rz ( ) R y ( )
Composing Transformation