7/27/2019 Lecture4 Transformation CoordSys
1/96
Computer Graphics
CS630
Lecture 3 Transformation And
Coordinate Systems
7/27/2019 Lecture4 Transformation CoordSys
2/96
2
What is a
Transformation? Maps points (x, y) in one coordinatesystem to points (x', y') in another
coordinate system
x' = ax + by + c
y' = dx + ey + f
7/27/2019 Lecture4 Transformation CoordSys
3/96
3
Transformations Simple transformation Translation
Rotation
Scaling
7/27/2019 Lecture4 Transformation CoordSys
4/96
4
Transformations Deformable transformations Shearing Tapering
Twisting Etc..
Issues Can be combined Are these operations invertible?
7/27/2019 Lecture4 Transformation CoordSys
5/96
5
Transformations Why use transformations? Position objects in a scene (modeling)
Change the shape of objects Create multiple copies of objects
Projection for virtual cameras
Animations
7/27/2019 Lecture4 Transformation CoordSys
6/96
6
Classes of
Transformation Rigid-Body/ Euclidean transformation Similarity Transforms
Linear Transforms Affine Transforms
Projective Transforms
7/27/2019 Lecture4 Transformation CoordSys
7/96
7
Rigid-Body / Euclidean
Transforms Preserves distances
Preserves angles
TranslationRotation
Rigid / Eucl idean
Identity
7/27/2019 Lecture4 Transformation CoordSys
8/96
8
How are Transforms
Represented?x' = ax + by + cy' = dx + ey + f
x'
y'
a b
d e
c
f=
x
y+
p' = Mp + t
7/27/2019 Lecture4 Transformation CoordSys
9/96
9
Translation
z
y
x
z
y
x
t
t
t
= +
z
y
x
tttT zyx ),,(
z
y
x
z
y
x
t
t
t
= +
'
'
'
z
y
x
7/27/2019 Lecture4 Transformation CoordSys
10/96
10
Properties of Translationv=v)0,0,0(T
=v),,(),,( zyxzyx tttTsssT
=
=v),,(1
zyx tttT
v),,(),,( zyxzyx tttTsssT v),,(),,( zyxzyx sssTtttT
v),,( zzyyxx tststsT
v),,( zyx tttT
7/27/2019 Lecture4 Transformation CoordSys
11/96
11
Scaling
zs
ys
xs
z
y
x
z
y
x
'
'
'
z
y
x
zyx
s
s
s
sssS
00
00
00
),,(
Uniform scaling i f f zyx sss
7/27/2019 Lecture4 Transformation CoordSys
12/96
12
Rotations (2D)
sin
cos
ry
rx
cos)sin(sin)cos('
sin)sin(cos)cos('
rry
rrx
)sin('
)cos('
ry
rx
cossinsincos)sin(
sinsincoscos)cos(
cossin'sincos'
yxyyxx
yx,
',' yx
x
y
7/27/2019 Lecture4 Transformation CoordSys
13/96
13
Rotations 2D So in matrix notation
y
x
y
x
cossin
sincos'
'
7/27/2019 Lecture4 Transformation CoordSys
14/96
14
Rotations (3D)
100
0cossin
0sincos
)(
cos0sin
010
sin0cos
)(
cossin0
sincos0
001
)(
z
y
x
R
R
R
7/27/2019 Lecture4 Transformation CoordSys
15/96
15
Properties of RotationsIRa )0(
)()()()( aaaa RRRR
)()()( aaa RRR
)()()(1 Taaa RRR
)()()()( abba RRRR order matters!
7/27/2019 Lecture4 Transformation CoordSys
16/96
16
Combining Translation &
Rotation
)1,1(T
)45( R
)45( R
)1,1(T
7/27/2019 Lecture4 Transformation CoordSys
17/96
17
Combining Translation &
RotationT vv'
RTR
TR
R
vv
vv
vv
''
)(''
'''
vv R'
TR
T
vv
vv
''
'''
7/27/2019 Lecture4 Transformation CoordSys
18/96
18
Homogeneous Coordinates
Add an extra dimension in 2D, we use 3 x 3 matrices
In 3D, we use 4 x 4 matrices
Each point has an extra value, w
x'
y'
z'w'
=
x
y
zw
a
e
im
b
f
jn
c
g
ko
d
h
lp
p' = Mp
7/27/2019 Lecture4 Transformation CoordSys
19/96
19
Homogeneous Coordinates
Most of the time w = 1, and we canignore it
x'
y'
z'
1
=
x
y
z
1
a
e
i
0
b
f
j
0
c
g
k
0
d
h
l
1
7/27/2019 Lecture4 Transformation CoordSys
20/96
20
Homogeneous
Coordinates
z
y
x
w
Z
Y
X
can be represented as
wherewZz
wYy
wXx ,,
7/27/2019 Lecture4 Transformation CoordSys
21/96
21
Translation Revisited
11000
100010
001
),,(zy
x
tt
t
z
y
x
tttTz
y
x
zyx
7/27/2019 Lecture4 Transformation CoordSys
22/96
22
Rotation & Scaling
Revisited
11000
000000
000
),,(zy
x
ss
s
z
y
x
sssSz
y
x
zyx
110000cossin0
0sincos0
0001
)(
z
y
x
z
y
x
Rx
7/27/2019 Lecture4 Transformation CoordSys
23/96
23
Combining
Transformations
vvvvvv
vvv
vv
MTRSTRT
RSR
S
'''''''''
'''
'
where TRSM
7/27/2019 Lecture4 Transformation CoordSys
24/96
24
Transforming Tangents
t
qp
qp
qpt
qpt
M
M
MM
)(
'''
7/27/2019 Lecture4 Transformation CoordSys
25/96
25
Transforming Normals
nnn
nnnn
tntn
tn
tn
tn
TT
T
TT
TT
T
T
T
MM
MM
M
M
11'
''
'
0'
0''
0
7/27/2019 Lecture4 Transformation CoordSys
26/96
26
Surface Normal Surface Normal: unit vector that is locallyperpendicular to the surface
7/27/2019 Lecture4 Transformation CoordSys
27/96
27
Why is the Normal
important? It's used for shading makes things look 3D!
object color only Diffuse Shading
7/27/2019 Lecture4 Transformation CoordSys
28/96
28
Visualization of Surface
Normal
x= Red y= Green z= Blue
7/27/2019 Lecture4 Transformation CoordSys
29/96
29
How do we transform
normals?
Object SpaceWorld Space
nOS
nWS
7/27/2019 Lecture4 Transformation CoordSys
30/96
30
Transform the Normallike the Ray?
translation?
rotation?
isotropic scale? scale?
reflection?
shear?
perspective?
7/27/2019 Lecture4 Transformation CoordSys
31/96
31
More Normal
Visualizations
Incorrect Normal Transformation Correct Normal Transformation
7/27/2019 Lecture4 Transformation CoordSys
32/96
32
Transforming Normals
nnn
nnnn
tntn
tn
tn
tn
TT
T
TT
TT
T
T
T
MM
MM
M
M
11'
''
'
0'
0''
0
7/27/2019 Lecture4 Transformation CoordSys
33/96
33
Rotations about an
arbitrary axisRotate by around a unit axis r
r
7/27/2019 Lecture4 Transformation CoordSys
34/96
34
An Alternative View We can view the rotation around anarbitrary axis as a set of simpler
steps We know how to rotate and translatearound the world coordinate system
Can we use this knowledge toperform the rotation?
7/27/2019 Lecture4 Transformation CoordSys
35/96
35
Rotation about an
arbitrary axis Translate the space so that the origin ofthe unit vector is on the world origin
Rotate such that the extremity of the
vector now lies in the xz plane (x-axisrotation)
Rotate such that the point lies in the z-axis (y-axis rotation)
Perform the rotation around the z-axis Undo the previous transformations
7/27/2019 Lecture4 Transformation CoordSys
36/96
36
Rotation about an
arbitrary axis Step 1Rotate x-axis
x
y
z
(a,b,c)
x
(a,b,c)
7/27/2019 Lecture4 Transformation CoordSys
37/96
37
Closer Look at Y-Z Plane Need to rotate degrees around thex-axis
y
z
7/27/2019 Lecture4 Transformation CoordSys
38/96
38
Equations for
||)1,0,0(||||),,0(||
)1,0,0(),,0()cos(
||),,0(||||)1,0,0(||
||),,0()1,0,0(||)sin(
cb
cb
cb
cb
7/27/2019 Lecture4 Transformation CoordSys
39/96
39
Rotation about the Y-
axis Using the same analysis as before, weneed to rotate degrees around the
Y-axis y
z
x
(a,b,c)=Rx () (a,b,c)T
7/27/2019 Lecture4 Transformation CoordSys
40/96
40
Equations for
||)1,0,0(||||)',','(||
)1,0,0()',','(
)cos(
||)',','(||||)1,0,0(||
||)',','()1,0,0(||)sin(
cba
cba
cba
cba
7/27/2019 Lecture4 Transformation CoordSys
41/96
41
Rotation about the Z-
axis Now, it is aligned with the Z-axis,thus we can simply rotate degrees
around the Z-axis. Then undo all the transformations wejust did
7/27/2019 Lecture4 Transformation CoordSys
42/96
42
Equation summary
c
ba
TRRRRRT
c
ba
rot xyzyxaxis )()()()()(
'
''
)( 111
7/27/2019 Lecture4 Transformation CoordSys
43/96
43
DeformationsTransformations that do not preserve
shape
Non-uniform scaling Shearing
Tapering
Twisting Bending
7/27/2019 Lecture4 Transformation CoordSys
44/96
44
Shearing
11000
01
01
01
1
'
'
'
z
y
x
ss
ss
ss
z
y
x
zyzx
yzyx
xzxy
0
0
0
1
zyzx
yzyx
xz
xy
ss
ss
s
s
x
y
x
y
7/27/2019 Lecture4 Transformation CoordSys
45/96
45
Tapering
11000
0)(00
00)(0
0001
1
'
'
'
z
y
x
xf
xf
z
y
x
7/27/2019 Lecture4 Transformation CoordSys
46/96
46
Twisting
11000
0))(cos(0))(sin(
0010
0))(sin(0))(cos(
1
'
'
'
z
y
x
yy
yy
z
y
x
7/27/2019 Lecture4 Transformation CoordSys
47/96
47
Bending
11000
0)()(0
0)()(0
0001
1
'
'
'
z
y
x
ykyh
ygyf
z
y
x
7/27/2019 Lecture4 Transformation CoordSys
48/96
48
Quick Recap Computer Graphics is using acomputer to generate an image from
a representation.Model Image
computer
7/27/2019 Lecture4 Transformation CoordSys
49/96
49
Modeling What we have been studying so far isthe mathematics behind the creation
and manipulation of the 3Drepresentation of the object.
Model Image
computer
7/27/2019 Lecture4 Transformation CoordSys
50/96
50
What have we seen so
far? Basic representations (point, vector) Basic operations on points and
vectors (dot product, cross products,etc.)
Transformation manipulative
operators on the basicrepresentation (translate, rotate,deformations) 4x4 matrices toencode all these.
7/27/2019 Lecture4 Transformation CoordSys
51/96
51
Why do we need this? In order to generate a picture from amodel, we need to be able to not only
specify a model (representation) butalso manipulate the model in order tocreate more interesting images.
7/27/2019 Lecture4 Transformation CoordSys
52/96
52
Overview The next set of slides will deal withthe other half of the process.
From a model, how do we generate animage
Model Imagecomputer
7/27/2019 Lecture4 Transformation CoordSys
53/96
53
Scene Description
Scene
LightsCamera ObjectsMaterialsBackground
7/27/2019 Lecture4 Transformation CoordSys
54/96
54
Graphics Pipeline
7/27/2019 Lecture4 Transformation CoordSys
55/96
55
Graphics Pipeline Modeling transforms orientthe models within a
common coordinate frame
(world space)
7/27/2019 Lecture4 Transformation CoordSys
56/96
56
Graphics Pipeline
7/27/2019 Lecture4 Transformation CoordSys
57/96
57
Graphics Pipeline Maps world space to eye space Viewing position is transformed
to origin & direction is oriented
along some axis (usually z)
7/27/2019 Lecture4 Transformation CoordSys
58/96
58
Graphics Pipeline Transform to Normalized DeviceCoordinates (NDC)
Portions of the object outside the
view volume (view frustum) areremoved
G hi
7/27/2019 Lecture4 Transformation CoordSys
59/96
59
Graphics
Pipeline The objects areprojected to the2D image place
(screen space)
7/27/2019 Lecture4 Transformation CoordSys
60/96
60
Graphics Pipeline
G hi
7/27/2019 Lecture4 Transformation CoordSys
61/96
61
Graphics
Pipeline Z-buffer - Eachpixel remembersthe closest object
(depth buffer)
7/27/2019 Lecture4 Transformation CoordSys
62/96
62
Graphics Pipeline Almost every step in the graphicspipeline involves a change of
coordinate system. Transformationsare central to understanding 3Dcomputer graphics.
7/27/2019 Lecture4 Transformation CoordSys
63/96
63
IntuitivelyObjectSpace
WorldSpace
Camera
Space+Projection
+NDC
Rasterization
7/27/2019 Lecture4 Transformation CoordSys
64/96
64
Coordinate Systems Object coordinates World coordinates
Camera coordinates Normalized device coordinates
Window coordinates
7/27/2019 Lecture4 Transformation CoordSys
65/96
65
Object CoordinatesConvenient place to model the object
O
7/27/2019 Lecture4 Transformation CoordSys
66/96
66
World CoordinatesCommon coordinates
for the scene
O
O
W
TSRMwo
Positioning Synthetic Camera
7/27/2019 Lecture4 Transformation CoordSys
67/96
67
Positioning Synthetic Camera
What are our degrees of freedom in camerapositioning?To achieve effective visual simulation, we want:1) the eye point to be in proximity of modeled scene2) the view to be directed toward region of interest,and3) the image plane to have a reasonable twist
Eye Coordinates
7/27/2019 Lecture4 Transformation CoordSys
68/96
68
Eye Coordinates
Eyepoint at originu axis toward right of image planevaxis toward top of image planeview direction along negativen axis
Transformation to Eye
7/27/2019 Lecture4 Transformation CoordSys
69/96
69
Transformation to EyeCoordinates
Our task: construct the transformation Mthat re-expresses world coordinates in theviewer frame
Machinery: Changing
7/27/2019 Lecture4 Transformation CoordSys
70/96
70
Machinery: ChangingOrthobases
Suppose you are given an
orthobasis u, v, nWhat is the action of thematrix M withrows u, v, and n as below?
A l i M t
7/27/2019 Lecture4 Transformation CoordSys
71/96
71
Applying M to u, v, n
Two equally valid interpretations, depending onreference frame:1: Think of uvn basis as a rigid object in a fixedworld spaceThen M rotates uvn basis into xyz basis
2: Think of a fixedaxis triad, with labels fromxyz spaceThen M reexpresses an xyz point p in uvncoords!It is this second interpretation that we use todayto relabel world-space geometry with eye space
coordinates
P iti i S th ti C
7/27/2019 Lecture4 Transformation CoordSys
72/96
72
Positioning Synthetic Camera
Given eyepoint e, basis u, v, nDeduce M that expresses world in eye coordinates:Overlay origins, then change bases:
P i i i S h i C
7/27/2019 Lecture4 Transformation CoordSys
73/96
73
Positioning Synthetic Camera
Check: does M re-express world geometry in eye coordinates?
P iti i S th ti C
7/27/2019 Lecture4 Transformation CoordSys
74/96
74
Positioning Synthetic Camera
Camera specification must include:World-space eye position eWorld-space lookat direction -n
Are e and -n enough to determine the camera DOFs(degrees of freedom)?
Positioning Synthetic
7/27/2019 Lecture4 Transformation CoordSys
75/96
75
Positioning SyntheticCamera
Are e and -n enough to determine the camera DOFs?No. Note that we were notgiven u and v!(Why not simply require the user to specify them?)
We must also determine u and v, i.e., camera twist about n.Typically done by specification of a world-space up vectorprovided by user interface, e.g., using gluLookat(e, c, up)Twist constraint: Align vwith world up vector (How?)
Positioning Synthetic
7/27/2019 Lecture4 Transformation CoordSys
76/96
76
Positioning SyntheticCamera
Where are we?
7/27/2019 Lecture4 Transformation CoordSys
77/96
77
Where are we?
What is Projection?
7/27/2019 Lecture4 Transformation CoordSys
78/96
78
What is Projection?
Any operation that reduces dimension (e.g., 3D to 2D)
Orthographic Projection
Perspective Projection
O th hi P j ti
7/27/2019 Lecture4 Transformation CoordSys
79/96
79
Orthographic Projection
focal point at infinity
rays are parallel and orthogonal to the image plane
Image
World
F
F
Image
World
I
W
7/27/2019 Lecture4 Transformation CoordSys
80/96
80
Comparison
Si l P ti C
7/27/2019 Lecture4 Transformation CoordSys
81/96
81
Simple Perspective Camera
camera looks along z-axis focal point is the origin
image plane is parallel to xy-plane at distance d
dis call focal length
Similar Triangles
7/27/2019 Lecture4 Transformation CoordSys
82/96
82
Similar TrianglesY
Z
[0, d][0, 0]
[Y, Z]
[(d/Z)Y, d]
Similar situation with x-coordinate
Similar Triangles:point [x,y,z] projects to [(d/z)x, (d/z)y, d]
Projection Matrix
7/27/2019 Lecture4 Transformation CoordSys
83/96
83
Projection MatrixProjection using homogeneous coordinates:
transform [x, y, z] to [(d/z)x, (d/z)y, d]
2-D image point: discard third coordinate
apply viewport transformation to obtainphysical pixel coordinates
d 0 0 0
0 d 0 0
0 0 d 0
0 0 1 0
x
y
z
1
dx dy dz z[ ] dzx
d
zy d
Divide by 4th coordinate
(the w coordinate)
Perspective Projection
7/27/2019 Lecture4 Transformation CoordSys
84/96
84
Perspective Projection
Perspective Projection
7/27/2019 Lecture4 Transformation CoordSys
85/96
85
Perspective Projection
z= 0 not allowed (what happens to points on plane z= 0?)Operation well-defined for all other points
Perspective Projection
7/27/2019 Lecture4 Transformation CoordSys
86/96
86
Perspective ProjectionMatrix formulation using homogeneous 4-vectors:
Finally, recover projected point using homogenous convention:Divide by 4thelement to convert 4-vector to 3-vector:
7/27/2019 Lecture4 Transformation CoordSys
87/96
87
Camera CoordinatesCoordinate system with the camera in a
convenient pose
1000
nr
vr
ur
zyx
zyx
zyx
cwnnn
vvvuuu
Mu
v
n
x
y
z
ew o ume anNormalized Device
7/27/2019 Lecture4 Transformation CoordSys
88/96
88
Normalized DeviceCoordinates
Normalized Device
7/27/2019 Lecture4 Transformation CoordSys
89/96
89
Normalized DeviceCoordinates
Device independent coordinates
Visible coordinate usually range from:
11
11
11
z
y
x
7/27/2019 Lecture4 Transformation CoordSys
90/96
90
Perspective ProjectionTaking the camera coordinates to NDC
z
x
near
7/27/2019 Lecture4 Transformation CoordSys
91/96
91
Perspective Projection
z
x
near'p
p
z
xnearx
z
x
near
x
'
'
Perspective Projection +
7/27/2019 Lecture4 Transformation CoordSys
92/96
92
Perspective Projection +NDC
0100
200
02
0
002
nearfar
nearfar
nearfar
nearfar
bottomtop
bottomtop
bottomtop
near
leftright
leftright
leftright
near
Mpc
7/27/2019 Lecture4 Transformation CoordSys
93/96
93
Window Coordinates
Adjusting the NDC to fit the window
),( 00 yx is the lower left of the window
7/27/2019 Lecture4 Transformation CoordSys
94/96
7/27/2019 Lecture4 Transformation CoordSys
95/96
95
Window Coordinates
1000
01002
02
0
200
2
0
0
_heightyheight
widthx
width
M pw
Summ : Obj ct C din t
7/27/2019 Lecture4 Transformation CoordSys
96/96
Summary : Object Coordinateto Device Coordinate
Take your representation (points) andtransform it from Object Space to WorldSpace (Mwo)
Take your World Space point andtransform it to Camera Space (Mcw) Perform the remapping and projection onto
the image plane in Normalized Device
Coordinates (Mw_pMpc) Perform this set of transformations on
each point of the polygonal object (M=M M M M )