Sunteți pe pagina 1din 96

Computer Graphics

CS630
Lecture 3 Transformation And
Coordinate Systems
2
What is a
Transformation?
Maps points (x, y) in one coordinate
system to points (x', y') in another
coordinate system
x' = ax + by + c
y' = dx + ey + f
3
Transformations
Simple transformation
Translation
Rotation
Scaling
4
Transformations
Deformable transformations
Shearing
Tapering
Twisting
Etc..

Issues
Can be combined
Are these operations invertible?
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

6
Classes of
Transformation
Rigid-Body/ Euclidean transformation
Similarity Transforms
Linear Transforms
Affine Transforms
Projective Transforms
7
Rigid-Body / Euclidean
Transforms

Preserves distances
Preserves angles
Translation
Rotation
Rigid / Euclidean
Identity
8
How are Transforms
Represented?
x' = ax + by + c
y' = dx + ey + f
x'
y'
a b
d e
c
f
=
x
y
+
p' = M p + t
9
Translation
(
(
(

z
y
x
(
(
(

z
y
x
t
t
t
= +
(
(
(

z
y
x
t t t T z y x ) , , (
(
(
(

z
y
x
(
(
(

z
y
x
t
t
t
= +
(
(
(

'
'
'
z
y
x
10
Properties of Translation
v = v ) 0 , 0 , 0 ( T
= v ) , , ( ) , , ( z y x z y x t t t T s s s T
=
=
v ) , , (
1
z y x t t t T

v ) , , ( ) , , ( z y x z y x t t t T s s s T v ) , , ( ) , , ( z y x z y x s s s T t t t T
v ) , , ( z z y y x x t s t s t s T + + +
v ) , , ( z y x t t t T
11
Scaling
(
(
(

=
(
(
(

z s
y s
x s
z
y
x
z
y
x
'
'
'
(
(
(

=
z
y
x
z y x
s
s
s
s s s S
0 0
0 0
0 0
) , , (
Uniform scaling iff z y x s s s = =
12
Rotations (2D)
|
|
sin
cos
r y
r x
=
=
u | u |
u | u |
cos ) sin ( sin ) cos ( '
sin ) sin ( cos ) cos ( '
r r y
r r x
+ =
=
) sin( '
) cos( '
u |
u |
+ =
+ =
r y
r x
u | u | u |
u | u | u |
cos sin sin cos ) sin(
sin sin cos cos ) cos(
+ = +
= +
|
u
u u
u u
cos sin '
sin cos '
y x y
y x x
+ =
=
y x,
' , ' y x
x
y
13
Rotations 2D
So in matrix notation
|
|
.
|

\
|
|
|
.
|

\
|

=
|
|
.
|

\
|
y
x
y
x
u u
u u
cos sin
sin cos
'
'
14
Rotations (3D)
(
(
(


=
(
(
(

=
(
(
(

=
1 0 0
0 cos sin
0 sin cos
) (
cos 0 sin
0 1 0
sin 0 cos
) (
cos sin 0
sin cos 0
0 0 1
) (
u u
u u
u
u u
u u
u
u u
u u u
z
y
x
R
R
R
15
Properties of Rotations
I Ra = ) 0 (
) ( ) ( ) ( ) ( u | | u a a a a R R R R =
) ( ) ( ) ( u | | u + = a a a R R R
) ( ) ( ) (
1
u u u
T
a a a R R R = =

) ( ) ( ) ( ) ( u | | u a b b a R R R R = order matters!
16
Combining Translation &
Rotation
) 1 , 1 ( T
) 45 ( R
) 45 ( R
) 1 , 1 ( T
17
Combining Translation &
Rotation
T + = v v'
RT R
T R
R
+ =
+ =
=
v v
v v
v v
' '
) ( ' '
' ' '
v v R = '
T R
T
+ =
+ =
v v
v v
' '
' ' '
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
z
w
a
e
i
m
b
f
j
n
c
g
k
o
d
h
l
p
p' = M p
19
Homogeneous Coordinates
Most of the time w = 1, and we can
ignore 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
20
Homogeneous
Coordinates
(
(
(

z
y
x
(
(
(
(

w
Z
Y
X
can be represented as
where
w
Z
z
w
Y
y
w
X
x = = = , ,
21
Translation Revisited
(
(
(
(

(
(
(
(

=
(
(
(

1 1 0 0 0
1 0 0
0 1 0
0 0 1
) , , (
z
y
x
t
t
t
z
y
x
t t t T
z
y
x
z y x
22
Rotation & Scaling
Revisited
(
(
(
(

(
(
(
(

=
(
(
(

1 1 0 0 0
0 0 0
0 0 0
0 0 0
) , , (
z
y
x
s
s
s
z
y
x
s s s S
z
y
x
z y x
(
(
(
(

(
(
(
(

=
(
(
(

1 1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
) (
z
y
x
z
y
x
Rx
u u
u u
u
23
Combining
Transformations
v v
v v v v
v v v
v v
M
TRS TR T
RS R
S
=
= = =
= =
=
' ' '
' ' ' ' ' '
' ' '
'
where TRS M =
24
Transforming Tangents
t
q p
q p
q p t
q p t
M
M
M M
=
=
=
=
=
) (
' ' '
25
Transforming Normals
n n n
n n
n n
t n t n
t n
t n
t n
T
T
T
T T
T T
T
T
T
M M
M
M
M
M
1
1
'
'
'
'
0 '
0 ' '
0

= =
=
=
=
=
=
=
26
Surface Normal
Surface Normal: unit vector that is locally
perpendicular to the surface
27
Why is the Normal
important?
It's used for shading makes things look 3D!
object color only Diffuse Shading
28
Visualization of Surface
Normal
x = Red
y = Green
z = Blue
29
How do we transform
normals?
Object Space World Space
n
OS
n
WS
30
Transform the Normal
like the Ray?
translation?
rotation?
isotropic scale?
scale?
reflection?
shear?
perspective?

31
More Normal
Visualizations
Incorrect Normal Transformation Correct Normal Transformation
32
Transforming Normals
n n n
n n
n n
t n t n
t n
t n
t n
T
T
T
T T
T T
T
T
T
M M
M
M
M
M
1
1
'
'
'
'
0 '
0 ' '
0

= =
=
=
=
=
=
=
33
Rotations about an
arbitrary axis
Rotate by around a unit axis
u
r
r
u
34
An Alternative View
We can view the rotation around an
arbitrary axis as a set of simpler
steps
We know how to rotate and translate
around the world coordinate system
Can we use this knowledge to
perform the rotation?
35
Rotation about an
arbitrary axis
Translate the space so that the origin of
the unit vector is on the world origin
Rotate such that the extremity of the
vector now lies in the xz plane (x-axis
rotation)
Rotate such that the point lies in the z-
axis (y-axis rotation)
Perform the rotation around the z-axis
Undo the previous transformations
36
Rotation about an
arbitrary axis
Step 1
Rotate x-axis
x
y
z
(a,b,c)
x
(a,b,c)
37
Closer Look at Y-Z Plane
Need to rotate o degrees around the
x-axis
o
y
z
38
Equations for o
|| ) 1 , 0 , 0 ( || || ) , , 0 ( ||
) 1 , 0 , 0 ( ) , , 0 (
) cos(
|| ) , , 0 ( || || ) 1 , 0 , 0 ( ||
|| ) , , 0 ( ) 1 , 0 , 0 ( ||
) sin(
c b
c b
c b
c b
-
=

=
o
o
39
Rotation about the Y-
axis
Using the same analysis as before, we
need to rotate | degrees around the
Y-axis

y
z
x
(a,b,c)=R
x
(o) (a,b,c)
T
40
Equations for |
|| ) 1 , 0 , 0 ( || || ) ' , ' , ' ( ||
) 1 , 0 , 0 ( ) ' , ' , ' (
) cos(
|| ) ' , ' , ' ( || || ) 1 , 0 , 0 ( ||
|| ) ' , ' , ' ( ) 1 , 0 , 0 ( ||
) sin(
c b a
c b a
c b a
c b a
-
=

=
|
|
41
Rotation about the Z-
axis
Now, it is aligned with the Z-axis,
thus we can simply rotate u degrees
around the Z-axis.
Then undo all the transformations we
just did
42
Equation summary
|
|
|
.
|

\
|
=
|
|
|
.
|

\
|
=

c
b
a
T R R R R R T
c
b
a
rot
x y z y x axis
) ( ) ( ) ( ) ( ) (
'
'
'
) (
1 1 1
o | u | o u
43
Deformations
Transformations that do not preserve
shape
Non-uniform scaling
Shearing
Tapering
Twisting
Bending
44
Shearing
(
(
(
(

(
(
(
(

=
(
(
(
(

1 1 0 0 0
0 1
0 1
0 1
1
'
'
'
z
y
x
s s
s s
s s
z
y
x
zy zx
yz yx
xz xy
0
0
0
1
= =
= =
=
=
zy zx
yz yx
xz
xy
s s
s s
s
s
x
y
x
y
45
Tapering
(
(
(
(

(
(
(
(

=
(
(
(
(

1 1 0 0 0
0 ) ( 0 0
0 0 ) ( 0
0 0 0 1
1
'
'
'
z
y
x
x f
x f
z
y
x
46
Twisting
(
(
(
(

(
(
(
(

=
(
(
(
(

1 1 0 0 0
0 )) ( cos( 0 )) ( sin(
0 0 1 0
0 )) ( sin( 0 )) ( cos(
1
'
'
'
z
y
x
y y
y y
z
y
x
u u
u u
47
Bending
(
(
(
(

(
(
(
(

=
(
(
(
(

1 1 0 0 0
0 ) ( ) ( 0
0 ) ( ) ( 0
0 0 0 1
1
'
'
'
z
y
x
y k y h
y g y f
z
y
x
48
Quick Recap
Computer Graphics is using a
computer to generate an image from
a representation.
Model
Image
computer
49
Modeling
What we have been studying so far is
the mathematics behind the creation
and manipulation of the 3D
representation of the object.
Model
Image
computer
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 basic
representation (translate, rotate,
deformations) 4x4 matrices to
encode all these.
51
Why do we need this?
In order to generate a picture from a
model, we need to be able to not only
specify a model (representation) but
also manipulate the model in order to
create more interesting images.
52
Overview
The next set of slides will deal with
the other half of the process.
From a model, how do we generate an
image
Model
Image
computer
53
Scene Description
Scene
Lights Camera

Objects
Materials
Background
54
Graphics Pipeline
55
Graphics Pipeline
Modeling transforms orient
the models within a
common coordinate frame
(world space)
56
Graphics Pipeline
57
Graphics Pipeline
Maps world space to eye space
Viewing position is transformed
to origin & direction is oriented
along some axis (usually z)
58
Graphics Pipeline
Transform to Normalized Device
Coordinates (NDC)
Portions of the object outside the
view volume (view frustum) are
removed

59
Graphics
Pipeline
The objects are
projected to the
2D image place
(screen space)



60
Graphics Pipeline
61
Graphics
Pipeline
Z-buffer - Each
pixel remembers
the closest object
(depth buffer)

62
Graphics Pipeline
Almost every step in the graphics
pipeline involves a change of
coordinate system. Transformations
are central to understanding 3D
computer graphics.

63
Intuitively
Object
Space
World
Space
Camera
Space
+Projection
+NDC
Rasterization
64
Coordinate Systems
Object coordinates
World coordinates
Camera coordinates
Normalized device coordinates
Window coordinates
65
Object Coordinates
Convenient place to model the object
O
66
World Coordinates
Common coordinates
for the scene
O
O
W
TSR M
wo
=
67
Positioning Synthetic Camera

What are our degrees of freedom in camera
positioning?
To achieve effective visual simulation, we want:
1) the eye point to be in proximity of modeled scene
2) the view to be directed toward region of interest,
and
3) the image plane to have a reasonable twist
68
Eye Coordinates

Eyepoint at origin
u axis toward right of image plane
v axis toward top of image plane
view direction along negative n axis
69
Transformation to Eye
Coordinates

Our task: construct the transformation M
that re-expresses world coordinates in the
viewer frame
70
Machinery: Changing
Orthobases

Suppose you are given an
orthobasis u, v, n
What is the action of the
matrix M with
rows u, v, and n as below?
71
Applying M to u, v, n

Two equally valid interpretations, depending on
reference frame:
1: Think of uvn basis as a rigid object in a fixed
world space
Then M rotates uvn basis into xyz basis
2: Think of a fixed axis triad, with labels from
xyz space
Then M reexpresses an xyz point p in uvn
coords!
It is this second interpretation that we use today
to relabel world-space geometry with eye space
coordinates
72
Positioning Synthetic Camera
Given eyepoint e, basis u, v, n
Deduce M that expresses world in eye coordinates:
Overlay origins, then change bases:
73
Positioning Synthetic Camera

Check: does M re-express world geometry in eye coordinates?
74
Positioning Synthetic Camera
Camera specification must include:
World-space eye position e
World-space lookat direction -n
Are e and -n enough to determine the camera DOFs
(degrees of freedom)?
75
Positioning Synthetic
Camera

Are e and -n enough to determine the camera DOFs?
No. Note that we were not given 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 vector
provided by user interface, e.g., using gluLookat(e, c, up)
Twist constraint: Align v with world up vector (How?)
76
Positioning Synthetic
Camera

77
Where are we?

78
What is Projection?

Any operation that reduces dimension (e.g., 3D to 2D)
Orthographic Projection
Perspective Projection
79
Orthographic Projection
focal point at infinity
rays are parallel and orthogonal to the image plane
Image
World
F
F
Image
World
I
W
80
Comparison
81
Simple Perspective Camera
camera looks along z-axis
focal point is the origin
image plane is parallel to xy-plane at distance d
d is call focal length
82
Similar Triangles
Y
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]
83
Projection Matrix
Projection 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 obtain
physical 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
| |
d
z
x
d
z
y d



(

(
Divide by 4th coordinate
(the w coordinate)
84
Perspective Projection

85
Perspective Projection

z = 0 not allowed (what happens to points on plane z = 0?)
Operation well-defined for all other points
86
Perspective Projection

Matrix formulation using homogeneous 4-vectors:
Finally, recover projected point using homogenous convention:
Divide by 4th element to convert 4-vector to 3-vector:
87
Camera Coordinates
Coordinate system with the camera in a
convenient pose
(
(
(
(




=
1 0 0 0
n r
v r
u r
z y x
z y x
z y x
cw
n n n
v v v
u u u
M
u
v
n
x
y
z
88
View Volume and
Normalized Device
Coordinates
89
Normalized Device
Coordinates
Device independent coordinates
Visible coordinate usually range from:
1 1
1 1
1 1
s s
s s
s s
z
y
x
90
Perspective Projection
Taking the camera coordinates to NDC
z
x
near
91
Perspective Projection
z
x
near
' p
p
z
x
near x
z
x
near
x
=
=

'
'
92
Perspective Projection +
NDC
(
(
(
(
(
(
(
(

=
0 1 0 0
2
0 0
0
2
0
0 0
2
near f ar
near f ar
near f ar
near f ar
bottom top
bottom top
bottom top
near
lef t right
lef t right
lef t right
near
M
pc
93
Window Coordinates
Adjusting the NDC to fit the window
) , ( 0 0 y x is the lower left of the window
94
Window Coordinates
Adjusting the NDC to fit the window
0
0
2
) 1 (
2
) 1 (
y
height
y y
x
width
x x
nd w
nd w
+
|
.
|

\
|
+ =
+
|
.
|

\
|
+ =
) , ( 0 0 y x is the lower left of the window
width
h
e
i
g
h
t

95
Window Coordinates
(
(
(
(
(
(

+
+
1 0 0 0
0 1 0 0
2
0
2
0
2
0 0
2
0
0
_
height
y
height
width
x
width
M
p w
96
Summary : Object Coordinate
to Device Coordinate
Take your representation (points) and
transform it from Object Space to World
Space (M
wo
)
Take your World Space point and
transform it to Camera Space (M
cw
)
Perform the remapping and projection onto
the image plane in Normalized Device
Coordinates (M
w_p
M
pc
)
Perform this set of transformations on
each point of the polygonal object (M=
M
w_p
M
pc
M
cw
M
wo
)

S-ar putea să vă placă și