2d Transformations
-
Upload
ashik-a-nezzilianz -
Category
Documents
-
view
218 -
download
0
description
Transcript of 2d Transformations
![Page 1: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/1.jpg)
CAP4730: Computational Structures in Computer Graphics
2D Transformations
![Page 2: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/2.jpg)
2D Transformations
• World Coordinates
• Translate
• Rotate
• Scale
• Viewport Transforms
• Putting it all together
![Page 3: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/3.jpg)
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
![Page 4: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/4.jpg)
Vertices
• We have always represented vertices as (x,y)
• An alternate method is:
• Example:
y
xyx ),(
8.4
1.2)8.4,1.2(
![Page 5: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/5.jpg)
Matrix * Vector
10
01
'
'
'
'
I
dycxy
byaxx
y
x
dc
ba
y
x
100
010
001
'
'
'
'
'
'
I
izhygxz
fzeydxy
czbyaxx
z
y
x
ihg
fed
cba
z
y
x
![Page 6: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/6.jpg)
Matrix * Matrix
10
01?
*
,
dc
ba
dwcydzcx
bwaybzaxBA
wz
yxB
dc
baA
Does A*B = B*A?
What does the identity do?
![Page 7: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/7.jpg)
Practice
?*
?*
5.23
15.0,
51
32
?
3
2,
51
32
IA
BA
BA
AX
XA
![Page 8: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/8.jpg)
Translation
• Translation - repositioning an object along a straight-line path (the translation distances) from one coordinate location to another.
(x,y)
(x’,y’)
(tx,ty)
![Page 9: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/9.jpg)
Translation
• Given:
• We want:
• Matrix form:TPP
t
t
y
x
y
x
tyy
txx
ttT
yxP
y
x
y
x
yx
'
'
'
'
'
),(
),(
1.4'
4.3'
2.8
1.7
1.4
7.3
'
'
2.81.4'
1.77.3'
)2.8,1.7(
)1.4,7.3(
y
x
y
x
y
x
T
P
![Page 10: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/10.jpg)
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’=(?,?)
![Page 11: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/11.jpg)
Which one is it?
(x,y)
(x’,y’)
(tx,ty)
(x,y)
(tx,ty)
![Page 12: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/12.jpg)
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.
![Page 13: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/13.jpg)
Applying to Triangles
(tx,ty)
![Page 14: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/14.jpg)
What do we have here?
• You know how to:
![Page 15: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/15.jpg)
Scale
• Scale - Alters the size of an object.
• Scales about a fixed point
(x,y)
(x’,y’)
![Page 16: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/16.jpg)
Scale
• Given:
• We want:
• Matrix form:PSP
y
x
s
s
y
x
ysy
xsx
ssS
yxP
y
x
y
x
yx
'
0
0
'
'
'
'
),(
),(
6.6'
2.4'
2.2
4.1
30
03
'
'
2.2*3'
4.1*3'
)3,3(
)2.2,4.1(
y
x
y
x
y
x
S
P
![Page 17: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/17.jpg)
Non-Uniform/Differential Scalin’
(x,y)
(x’,y’)
S=(1,2)
![Page 18: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/18.jpg)
Rotation
• Rotation - repositions an object along a circular path.
• Rotation requires an and a pivot point
![Page 19: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/19.jpg)
Rotation
)cos('
)cos('
sin
cos
)(
),(
ry
rx
ry
rx
R
yxP
PRP
y
x
y
x
yxy
yxx
rry
rrx
'
cossin
sincos
'
'
cossin'
sincos'
cossinsincos'
sinsincoscos'
![Page 20: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/20.jpg)
Example
• P=(4,4)=45 degrees
![Page 21: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/21.jpg)
What is the difference? RevisitedV(-0.6,0) V(0,-0.6) V(0.6,0.6)
Translate (1.2,0.3)
V(0,0.6) V(0.3,0.9) V(0,1.2)
Translate (1.2,0.3)
V(0.6,0.3) V(1.2,-0.3) V(1.8,0.9)
V(0,0.6) V(0.3,0.9) V(0,1.2)
![Page 22: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/22.jpg)
RotationsV(-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)
![Page 23: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/23.jpg)
Combining Transformations
Q: How do we specify each transformation?
![Page 24: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/24.jpg)
Specifying 2D Transformations
• Translation– T(tx, ty)
– Translation distances
• Scale– S(sx,sy)
– Scale factors
• Rotation– R()– Rotation angle
![Page 25: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/25.jpg)
Combining Transformations
• Using translate, rotation, and scale, how do we get:
![Page 26: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/26.jpg)
Combining Transformations• Note there are two ways to combine
rotation and translation. Why?
![Page 27: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/27.jpg)
Let’s look at the equations
cos'sin'"
sin'cos'"
'
'
'''
'
)(
),(
),(
yxy
yxx
tyy
txx
PRP
TPP
R
ttT
yxP
y
x
yx
y
x
yx
yx
tyxy
tyxx
yxy
yxx
TPP
PRP
tytxy
tytxx
cossin"
sincos"
cossin'
sincos'
'"
'
cos'sin"
sin'cos"
![Page 28: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/28.jpg)
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 don’t we just combine them?
PSP
PRP
TPP
'
'
'
![Page 29: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/29.jpg)
2x2 -> 3x3 Matrices
• We can combine transformations by expanding from 2x2 to 3x3 matrices.
100
0cossin
0sincos
cossin
sincos
100
00
00
0
0,
100
10
01
,
R
s
s
s
sssS
t
t
t
t
y
xttT
y
x
y
x
yx
y
x
y
x
yx
![Page 30: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/30.jpg)
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.
2
22
147
2
63
2
14
6
7
3.,
1
2
4
2
4. ExEx
h
hh
yy
h
xx
h
y
x
y
xP h
h
h
h
![Page 31: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/31.jpg)
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.
![Page 32: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/32.jpg)
Final Transformations - Compare Equations
PRPPRP
y
x
y
x
y
x
y
xR
PssSPPssSP
y
x
s
s
y
x
y
x
s
s
y
xssS
PttTPPttTP
y
x
t
t
y
x
y
x
t
t
y
xttT
yxyx
y
x
y
x
yx
yxyx
y
x
y
x
yx
1100
0cossin
0sincos
1
'
'
cossin
sincos
'
'
,,
1100
00
00
1
'
'
0
0
'
',
,,
1100
10
01
1
'
'
'
',
![Page 33: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/33.jpg)
Combining Transformations
1
'
'
100
10
01
100
0cossin
0sincos
1
"
"
1
'
'
100
0cossin
0sincos
1
"
"
1100
10
01
1
'
'
)60(),2,4641.0(),4,3(
"'",'
y
x
t
t
y
x
y
x
y
x
y
x
t
t
y
x
RTP
PBAPPBPPAP
y
x
y
x
1100
cossin
sincos
1
"
"
1100
0cossin
0sincos
100
10
01
1
"
"
1100
cossincossin
sincossincos
1
"
"
y
x
t
t
y
x
y
x
t
t
y
x
y
x
tt
tt
y
x
y
x
y
x
yx
yx
![Page 34: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/34.jpg)
How would we get:
![Page 35: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/35.jpg)
How would we get:
![Page 36: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/36.jpg)
Coordinate Systems
• Object Coordinates
• World Coordinates
• Eye Coordinates
![Page 37: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/37.jpg)
Object Coordinates
![Page 38: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/38.jpg)
World Coordinates
![Page 39: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/39.jpg)
Screen Coordinates
![Page 40: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/40.jpg)
Coordinate Hierarchy
O b jec t #1O b jec t C oo rd in a tes
T ra n sfo rm a tionO b je ct # 1 ->
W o rld
O b jec t #2O b jec t C oo rd in a tes
T ra n sfo rm a tionO b je ct # 2 ->
W o rld
O b jec t #3O b jec t C oo rd in a tes
T ra n sfo rm a tionO b je ct # 3 ->
W o rld
W o rld C o o rd in a tes
T ra n sfo rm a tionW o rld -> S c re en
S c re en C oo rd in a tes
![Page 41: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/41.jpg)
Let’s reexamine assignment 2b
![Page 42: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/42.jpg)
Transformation Hierarchies
• For example:
![Page 43: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/43.jpg)
Transformation Hierarchies
• Let’s examine:
![Page 44: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/44.jpg)
Transformation Hierarchies
• What is a better way?
![Page 45: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/45.jpg)
Transformation Hierarchies
• What is a better way?
![Page 46: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/46.jpg)
Transformation Hierarchies
• We can have transformations be in relation to each other
B lueO b jec t C oo rd in a tes
T ra n sfo rm a tionB lu e -> R ed
R edO b jec t C oo rd in a tes
T ra n sfo rm a tionR e d -> G re en
G re enO b je ct 's C o o rd in a tes
T ra n sfo rm a tionG re e n -> W o rld
W o rld C o o rd in a tes
![Page 47: 2d Transformations](https://reader036.fdocuments.us/reader036/viewer/2022062804/55cf8ee6550346703b96cd60/html5/thumbnails/47.jpg)
More Complex Models