CAP4730: Computational Structures in Computer Graphics
CAP4730: Computational Structures in Computer Graphics
2D Transformations
2D Transformations
World Coordinates
Translate
Rotate
Scale
Viewport Transforms
Putting it all together
Transformations
Rigid Body Transformations - transformations that do
not change the object.
Translate
If you translate a rectangle, it is still a rectangle
Scale
If you scale a rectangle, it is still a rectangle
Rotate
If you rotate a rectangle, it is still a rectangle
Vertices
We have always represented vertices as
(x,y)
An alternate method is:
x
( x, y )
y
Example:
2.1
(2.1,4.8)
4
.
8
Matrix * Vector
x' a b x
y ' c d y
x' ax by
y ' cx dy
1 0
I
0
1
x' a b c
y ' d e f
z ' g h i
x' ax by cz
y ' dx ey fz
z ' gx hy iz
1 0 0
I 0 1 0
0 0 1
x
y
z
Matrix * Matrix
a b
A
,B
c d
ax bz
A* B
cx dz
a b 1 0
?
0 1
c
d
x y
z w
ay bw
cy dw
Practice
2 3
2
A
,X
1
5
AX ?
2 3
0.5 1
A
,B
1
5
3
2
.
5
A* B ?
A* I ?
Translation
Translation - repositioning an object along a
straight-line path (the translation
distances) from one coordinate location to
another.
(x,y)
(tx,ty)
(x,y)
Translation
Given:
We want:
Matrix form:
P ( x, y )
T (t x , t y )
x' x t x
y' y t y
x' x t x
y ' y t
y
P' P T
P (3.7,4.1)
T (7.1,8.2)
x' 3.7 7.1
y ' 4.1 8.2
x' 3.7 7.1
y ' 4.1 8.2
x' 3.4
y ' 4.1
Translation Examples
P=(2,4), T=(-1,14), P=(?,?)
P=(8.6,-1), T=(0.4,-0.2), P=(?,?)
P=(0,0), T=(1,0), P=(?,?)
(tx,ty)
(x,y)
Recall
A point is a position specified with
coordinate values in some reference frame.
We usually label a point in this reference
point as the origin.
All points in the reference frame are given
with respect to the origin.
Applying to Triangles
(tx,ty)
Scale
Scale - Alters the size of an object.
Scales about a fixed point
(x,y)
(x,y)
Scale
Given:
We want:
Matrix
P ( x, y )
S (sx , s y )
P (1.4,2.2)
S (3,3)
x' s x x
x' 3 *1.4
y ' 3 * 2.2
y' s y y
x' s x
y ' 0
form:
P' S P
0
s y
x
y
x' 3 0 1.4
y ' 0 3 2.2
x' 4.2
y ' 6.6
Non-Uniform/Differential Scalin
(x,y)
(x,y)
S=(1,2)
Rotation
Rotation - repositions an object along a
circular path.
Rotation requires an and a pivot point
Rotation
P ( x, y )
R ( )
x r cos
y r sin
x' r cos( )
y ' r cos( )
sin
cos
x
y
Example
P=(4,4)
=45 degrees
Translate (1.2,0.3)
Translate (1.2,0.3)
Rotations
V(-0.6,0) V(0,-0.6) V(0.6,0.6)
Rotate -30 degrees
V(0,0.6) V(0.3,0.9) V(0,1.2)
Combining Transformations
Q: How do we
specify each
transformation?
Specifying 2D Transformations
Translation
T(tx, ty)
Translation distances
Scale
S(sx,sy)
Scale factors
Rotation
R()
Rotation angle
Combining Transformations
Using translate, rotation, and scale, how do
we get:
Combining Transformations
P' R P
P" P 'T
x' x cos y sin
y ' x sin y cos
x" x cos y sin t x
Combining them
We must do each step in turn. First we
rotate the points, then we translate, etc.
Since we can represent the transformations
by matrices, why dont we just combine
them?
P' P T
P' R P
P' S P
s x 0 0
s
0
x
S sx , s y
0 s y 0
0 s y 0 0 1
cos
sin
cos
sin
sin
cos
0
sin
cos
0
0
1
Homogenous Coordinates
We need to do something to the vertices
By increasing the dimensionality of the
problem we can transform the addition
component of Translation into
multiplication.
x
P
y
xh
yh
h
xh
x
4
yh
y Ex.
h
2 , Ex.
6
14
2
6
3
14
7
2
2
2
Homogenous Coordinates
Homogenous Coordinates - term used in
mathematics to refer to the effect of this
representation on Cartesian equations. Converting a
pt(x,y) and f(x,y)=0 -> (xh,yh,h) then in homogenous
equations mean (v*xh,v*yh,v*h) can be factored out.
What you should get: By expressing the
transformations with homogenous equations and
coordinates, all transformations can be expressed as
matrix multiplications.
T t x , t y y ' 0 1 t y y
y ' t y y
1 0 0 1 1
P T t x , t y P P T tx , t y P
x' s x
x'
x
y ' 0
S sx , s y
y
y '
1 0
P S sx , s y P P S sx , s y P
sx
0
x' cos
y ' sin
0
s y
sin x
cos y
P R P P R P
0
sy
0
x' cos
y ' sin
1 0
0
0
x
y
1 1
sin
cos
0
0 x
0 y
1 1
Combining Transformations
P ' A P, P" B P ' P" A B P
P (3,4), T (0.4641,2), R(60)
x' 1 0 t x x
y ' 0 1 t y
y
1 0 0 1 1
x" cos sin
y" sin cos
1 0
0
0
0
1
x'
y '
1
x" cos
y" sin
1 0
0
0
1
1 0 tx
0 1 t
y
0 0 1
sin
cos
0
x"
y"
1
x"
y"
1
x '
y '
1
x"
y"
1
cos
sin
0
sin
cos
0
t x cos t y sin
t x sin t y cos
1 0 t x cos sin
0 1 t y sin cos
0 0 1 0
0
cos sin t x x
sin cos t y y
0
0
1 1
0
0
1
x
y
1
x
y
1
Coordinate Systems
Object Coordinates
World Coordinates
Eye Coordinates
Object Coordinates
World Coordinates
Screen Coordinates
Coordinate Hierarchy
S c r e e n C o o r d in a t e s
T r a n s f o r m a t io n
W o r ld - > S c r e e n
W o r ld C o o r d in a t e s
T r a n s f o r m a t io n
O b je c t # 1 ->
W o r ld
T r a n s f o r m a t io n
O b je c t # 2 ->
W o r ld
T r a n s f o r m a t io n
O b je c t # 3 ->
W o r ld
O b je c t # 1
O b j e c t C o o r d in a t e s
O b je c t # 2
O b j e c t C o o r d in a t e s
O b je c t # 3
O b j e c t C o o r d in a t e s
Transformation Hierarchies
For example:
Transformation Hierarchies
Lets examine:
Transformation Hierarchies
What is a better way?
Transformation Hierarchies
What is a better way?
Transformation Hierarchies
We can have transformations be
in relation to each other
W o r ld C o o r d in a t e s
T r a n s f o r m a t io n
G r e e n - > W o r ld
G re e n
O b je c t 's C o o r d in a t e s
T r a n s f o r m a t io n
R e d -> G re e n
R ed
O b j e c t C o o r d in a t e s
T r a n s f o r m a t io n
B lu e -> R e d
B lu e
O b j e c t C o o r d in a t e s