View
223
Download
0
Category
Preview:
Citation preview
8/12/2019 Kom Graf 04 Transform as i
1/28
Gasal 2013/2014KOMPUTER GRAFIK (3SKS)
Cucun Very Angkoso,ST.,MT
:: Pertemuan ke ::
8/12/2019 Kom Graf 04 Transform as i
2/28
TRANSFORMASI 2D
Transformasi adalah fungsi yang memetakan suatu set X ke set yanglain ataupun ke set X sendiri. Terdapat banyak jenis operasi
transformasi: translasi, refleksi, rotasi, scaling, shearing.
A transformation maps points to other points and/or vectors to
other vectors
v=T(u)
8/12/2019 Kom Graf 04 Transform as i
3/28
A1. Matriks Translasi
1
y
x
.t
t
'y
'x
y
x
100
10
01
1
A2. Matriks Rotasi
1
yx
.
100
0cossin0sincos
1
''
y
x
A3. Matriks Skala
1
y
x
.s
s
'y
'x
y
x
100
00
00
1
atau P = T(tx, ty) . P
atau P = R() . P
atau P = S(sx, sy) . P
8/12/2019 Kom Graf 04 Transform as i
4/28
Rotasi
Arah rotasi berlawanan dengan arah putar jarum jam, arahputarnya dikatakan Positif
Sebaliknya, jika arah rotasi searah dengan arah putar
jarum jam, arah putarnya dikatakan negatif
8/12/2019 Kom Graf 04 Transform as i
5/28
Transformasi Geometri (Rotasi)
1. Titik Q(-1, 4) diputar searah jarum jam terhadap titik pusat O,tentukanbayangan titik Q oleh rotasi (O, 450)
Jawab:
= - 450
x = x cos - y sin= -1 Cos (- 450)4 sin (- 450)
= - - 4 . (- )
= - + 2
=
y = x sin + y cos= -1 Sin(-450) + 4 Cos(-450)
= -1(- ) + 4 .
= + 2
= 5/2
2
2
3
2
2
22
Jadi Q (3/2 , 5/2 )22
2
2
2
2
2
8/12/2019 Kom Graf 04 Transform as i
6/28
8/12/2019 Kom Graf 04 Transform as i
7/28
Bagaimana urutan transformasi yang diperlukan untuk
mewujudkannya?
8/12/2019 Kom Graf 04 Transform as i
8/28
8/12/2019 Kom Graf 04 Transform as i
9/28
8/12/2019 Kom Graf 04 Transform as i
10/28
10
Pipeline Implementation
transformation rasterizer
u
v
u
v
T
T(u)
T(v)
T(u)
T(u)
T(v)
T(v)
vertices vertices pixels
frame
buffer
(from application program)
8/12/2019 Kom Graf 04 Transform as i
11/28
11
Translation Matrix
Express translation using a
4 x 4 matrix Tin homogeneous coordinates
p=Tpwhere
T = T(dx, dy, dz) =
This form is better for implementation because all affinetransformations can be expressed this way and multipletransformations can be concatenated together
1000
d100
d010
d001
z
y
x
8/12/2019 Kom Graf 04 Transform as i
12/28
12
Rotation (2D)
Consider rotation about the origin by degrees radius stays the same, angle increases by
x=x cos y sin
y = x sin + y cos
x = r cos f
y = r sin f
x = r cos (f + )
y = r sin (f + )
8/12/2019 Kom Graf 04 Transform as i
13/28
13
Rotation about the zaxis
Rotation about zaxis in three dimensions leavesall points with the same z
Equivalent to rotation in two dimensions in planes of
constant z
or in homogeneous coordinates
p=Rz()p
x=x cos y sin
y = x sin + y cos z =z
8/12/2019 Kom Graf 04 Transform as i
14/28
14
Rotation Matrix
1000
0100
00cossin
00sincos
R= Rz() =
8/12/2019 Kom Graf 04 Transform as i
15/28
15
Rotation about xand yaxes
Same argument as for rotation about zaxis For rotation about xaxis, xis unchanged
For rotation about yaxis, yis unchanged
R= Rx() =
R= Ry() =
1000
0cossin0
0sin-cos0
0001
1000
0cos0sin-
0010
0sin0cos
8/12/2019 Kom Graf 04 Transform as i
16/28
16
Scaling
1000
000000
000
z
y
x
s
s
s
S = S(sx, sy, sz) =
x=sxx
y=syx
z=szx
p=Sp
Expand or contract along each axis (fixed point of origin)
8/12/2019 Kom Graf 04 Transform as i
17/28
17
Reflection
corresponds to negative scale factors
originalsx= -1 sy= 1
sx= -1 sy= -1 sx= 1 sy= -1
8/12/2019 Kom Graf 04 Transform as i
18/28
18
Inverses
Although we could compute inverse matrices bygeneral formulas, we can use simple geometric
observations
Translation: T-1(dx, dy, dz)= T(-dx, -dy, -dz)
Rotation: R-1
() = R(-) Holds for any rotation matrix
Note that since cos(-) = cos() and sin(-)=-sin()
R-1() = R T()
Scaling: S-1(sx, sy, sz)= S(1/sx, 1/sy, 1/sz)
8/12/2019 Kom Graf 04 Transform as i
19/28
19
Concatenation
We can form arbitrary affine transformationmatrices by multiplying together rotation,
translation, and scaling matrices
Because the same transformation is applied to
many vertices, the cost of forming a matrixM=ABCDis not significant compared to the cost of
computing Mpfor many vertices p
The difficult part is how to form a desired
transformation from the specifications in theapplication
8/12/2019 Kom Graf 04 Transform as i
20/28
20
Order of Transformations
Note that matrix on the right is the first applied
Mathematically, the following are equivalent
p = ABCp= A(B(Cp))
Note many references use column matrices to
represent points. In terms of column matricespT= pTCTBTAT
8/12/2019 Kom Graf 04 Transform as i
21/28
21
General Rotation About the Origin
x
z
y
v
A rotation by about an arbitrary axis
can be decomposed into the concatenation
of rotations about thex, y, and zaxes
R() = Rz(z) Ry(y) Rx(x)
x y z are called the Euler anglesNote that rotations do not commute
We can use rotations in another order but
with different angles
8/12/2019 Kom Graf 04 Transform as i
22/28
22
Rotation About a Fixed Point other than the
Origin
Move fixed point to originRotate
Move fixed point back
M= T(pf) R() T(-pf)
8/12/2019 Kom Graf 04 Transform as i
23/28
23
Shear
Helpful to add one more basic transformation Equivalent to pulling faces in opposite directions
8/12/2019 Kom Graf 04 Transform as i
24/28
24
Shear Matrix
Consider simple shear along xaxis
x = x + y cot
y = y
z = z
1000
0100
0010
00cot1
H() =
8/12/2019 Kom Graf 04 Transform as i
25/28
Transformasi Pada OpenGL
In OpenGL matrices are part of the stateMultiple types
Model-View (GL_MODELVIEW)
Projection (GL_PROJECTION)
Texture (GL_TEXTURE) (ignore for now)Color(GL_COLOR) (ignore for now)
Single set of functions for manipulation
Select which to manipulated byglMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
8/12/2019 Kom Graf 04 Transform as i
26/28
8/12/2019 Kom Graf 04 Transform as i
27/28
Tugas..Menggambarkan Orbit Bumi dan Bulan
8/12/2019 Kom Graf 04 Transform as i
28/28
Tugas..Menggambarkan Gerakan Tutup Gelas Terbuka
Gelas tertutup Gelas terbukaGerakan terbuka dantertutup
Recommended