Khoa CNTT - DDHBK Hà ni
hunglt@it-hut.edu.vn
8682595
1
1
Bài 4 Các phép biếnđổiĐồ ho
Transformations
Le Tan Hung
Email: hunglt@it-hut.edu.vn
2
Phép biếnđổi - Transformations
zTrong kthutđồ ho3 bước: Mô hình, Tô trát
vàHiên th(modeling, rendering, displaying)
zVi Modeling ( Mô hình hóa) :
zTransformation: là phép ánh xtađộ đim hay
vector thành tađộ hay vector khác
modeling
coordinate Modeling
transformation
Viewing
transformation
world
coordinate
viewing
coordinate (eye
coordinate)
3
Phép biến đổi Transformations
zBiến đổi mô hình hoá - Modeling transformations
build complex models by positioning simple
components
zBiến đổi to góc nhìn - Viewing transformations
placing virtual camera in the world
transformation from world coordinates to camera
coordinates
zBiến Phép chiếu – Projection Transform
4
Transformations - Modeling
world
5
Phép biếnđổi Affine
Affine Transformations?
zPhép biếnđổiAffine là phép biếnđổita độ
đimđặctrưng cađốitượng thành tptương
ng các đimmiđể toracáchiung cho
toàn đốitượng.
Víd: phép biếnđổitađộ vich2 đimđầucuica
đonthng to thành 2 đimmimàkhini chúng vi
nhau to thành đonthng mi.
zCác đimnmtrênđonthng s kếtqu
đimnmtrênđonthng mivi cùng phép biến
đổi thông qua phép nisuy.
6
Modeling Transformations
Transform
objects/points
Transform coordinate system
Khoa CNTT - DDHBK Hà ni
hunglt@it-hut.edu.vn
8682595
2
7
Biu din Ma trn
zVic biến đối các đối tượng làm thay đổi các
đim P thành các đim Q theo thut toán
zVic biến đổi P s dng ta độ ca P (Px,Py) ánh
x thành các ta độ mi Q(Qx,Qy)
zVic biến đổi có th biu din thông qua hàm T,
hàm ánh x ca đim:
T(Px,Py) = (Qx,Qy)
or:
T(P) = Q
8
Matrix Representation
zPhép biến đổi đồ ha - affine transformation T ánh x
tp P sang tp Q:
where a, b,c,d, tx and ty là các h s
zBiu din ma trn:
zi.e.
+
=
y
x
y
x
y
x
t
t
P
P
dc
ba
Q
Q
xxxx t bP aP Q +
+
=
yyyy t dP cP Q ++=
Tr MP Q +
=
9
Các phép biếnđổihìnhhchai
chiu
zPhương pháp biudinđốitượng P = [ x y ]
zPhép biếnđổivtrí đim
zThc thi phép biếnđổiđúngtrên1 đimnh sẽđúng
trên toàn bộđitượng
=dc
ba
T
[][][ ]
()( )
[]
[]
'' y dybx *y * xcyax
dc
ba
xTX =++=
=
y
x
z
pM
pW
10
Phép biếnđổi
zPhép btbiến
zPhép biếnđổitl- Scaling
zA scaling changes the size of an object with two scale
factors, Sxand Sy
zPhép biếndng
zA shearing shears an object in a particular direction, (in
2D, it’s either in the x or in the y direction
=10
01
T
[][][ ]
()
[][]
''
10
0
** yxyax
a
yxTX ==
=
[][][ ] [ ][ ]
''
10
1
** yxdybx
b
yxTX =+=
=
x
z
y
11
Phép quay- Rotation
x = ρcos α, y = ρsin α;
x’ = ρcos (θ+α), y’ = ρsin (θ+α) ;
x’ = ρ( cosθcosα-sinθsinα)
= x cosθ- y sinθ
y’ = ρ( sinθcosα+ cosθsinα)
= x sinθ+ y cosθ
[x' y']= [xcosθ- ysinθxsinθ+ ycosθ]
y
(x, y )
x
α
ρ
θ
ρ
( x’, y’ )
=
θθ
θθ
cossin
sincos
][T
12
Thuc tính cơ bn ca phép biến
đổi Affine Transformations
zPreservation of lines:
They preserve lines, so the image of a straight line is
another straight line.
This vastly simplifies drawing transformed line
segments.
We need only compute the image of the two endpoints
of the original line and then draw a straight line between
them
Preservation of collinearity guarantees that polygons will
transform into polygons
Affine transformations map lines to lines;
Khoa CNTT - DDHBK Hà ni
hunglt@it-hut.edu.vn
8682595
3
13
Thuc tính
zPreservation of parallelism
Preservation of parallelism guarantees that
parallelograms will transform into parallelograms
zPreservation of proportional distances
Preservation of proportional distances means that mid-
points of lines remain mid-points
zAffine transformations change volume by |
Det(M) |;
14
Kếthp các phép biếnđổi
Composition of Affine Transforms
zAny affine transformation can be
decomposed into elementary
transformations.
zMi phép biếnđổiphctpđều
thto thành tcác phép biến
đổicơsnhư:
Dch chuyn - Translation
Tl- Scaling
Quay- Rotation
Biếndng - Shearing
15
Affine transformations preserve
affine combinations
zIt is rare that we want to perform just one elementary
transformation.
zUsually an application requires that we build a
complex transformation out of several elementary
ones
e.g. translate an object, rotate it, and scale it, all in one move
zThese individual transformations combine into one
overall transformation
zThis is called the composition of transformations.
zThe composition of two or more affine transformations
is also an affine transformation
16
Thuc tính
zTác động lên tp các đim đặc trưng ca đối
tượng to thành phép biến đổi cho đối tượng
zWe have defined each transformation by their effects on
single points
zIn practice these will be applied to multiple points to
transfer entire scenes or objects made up of many
defining points
T
17
Đim gc - Pivotal points
Cho phép quay và t l Rotation and Scaling
zThe simple versions of rotation and scaling have been based around the
origin.
zThis means that when we rotate or scale, the object will also move, with
respect to the origin
zTranslate all points through (-c1,-c2)
zRotate all points about the origin by
zTranslate all points back through (c1,c2)
(c1,c2)
(0,0) 18
Pivotal points
zOften we wish to rotate or scale with respect to some
pivotal point, not the origin
zMost significantly, we often wish to rotate or scale an
object about its centre, or midpoint
zIn this way, the object’s location does not change
zTo do this, we relate the rotation or scaling about the
pivotal point V, to an elementary rotation or scaling about
the origin
We first translate all points so that V coincides with the origin
We then rotate or about the origin
then all points are translated back, so that V is restored to its
original location
Khoa CNTT - DDHBK Hà ni
hunglt@it-hut.edu.vn
8682595
4
19
H to độ đồng nht
zVn đề gp phi:
zAn affine transformation is composed of a linear
transformation followed by a translation
zUnfortunately, the translation portion is not a
matrix multiplication but must instead be added as
an extra term, or vector
zWhat we need is a “trick”, so that translations can
be represented in matrix multiplication form
zThis then means that they can be easily
composed with other transformations, by simply
multiplying the matrices together 20
Tađộ đồng nht
Homogeneous Transform
x' = ax + by + n
y' = cx + dy + m
zPhương pháp biudinmrng thông qua
tađộ đồng nhtca các vector vtrí
zVing dng ca phép chiếuhìnhhcmà
đótađộ đimđượcmôtdướima trn[
x* y* h]
vi x = x*/h, y = y*/h, z = z*/h và h là mts
thctuý
21
ƯuđimcaHtađộ đồng nht
Homogeneous Transform
zÐưaracáinhìnhpnhtca các phép biếnđổi
dưới phép nhân ma trn, htrcho vicx
bng cphncng phnmm
zKếthp các các phép biếnđổito thành ma trn
tích đơngin duy nht. Tránh nhmlnvtht
ca các phép nhân khi sdng.
Order matters: AB is generally not the same as BA
zCho phép kếthpviccác phép biếnđổiđặc
bit không tuyến tính khác(non-affine) như:
Phép chiếuphicnh - Perspective projections!
Un - Bends, Vut tapers v.v.v
22
Phép biếnđổivitađộ đng nht
zMa trnbiếnđổiđồng nht
zPhép tnh tiến
=
1
0
0
][
nm
dc
ba
T
]1[
1
010
001
]1[]1''[ nymx
nm
yxyx ++=
=
(tx, ty, tz)
23
Phép tl
]12.1.[
100
020
001
]1[]1''[ SySxS
S
yxyx =
=
24
Phép quay
y
(x, y )
x
α
ρ
θ
ρ
( x’, y’ )
=
100
0cossin
0sincos
]1[]1''[
φφ
φφ
yxyx
]1cos.sin.sin.cos.[
φφφφ
yxyx +=
Khoa CNTT - DDHBK Hà ni
hunglt@it-hut.edu.vn
8682595
5
25
Phép biếnđổitng hp
26
Ma trn biến đổi 3 chiu
3D Matrix Transformations
zCác phép biến đổi chuyn v - translation, t l-
scaling và quay-rotation s dng trong không
gian 2D đều co th m rng trong không gian 3D
zAgain, using homogeneous coordinates it is
possible to represent each type of transformation
in a matrix form
zIn 3D, each transformation is represented by a
4x4 matrix
27
Các phép biếnđổihìnhhc3 chiu
zBiudinđim trong không gian 3 chiu
z[ x* y* z* h ] = [ x y z 1 ]. [ T ]
z[x' y' z' 1 ]= [ x*/h y*/h z*/h 1 ][ T ]
zMa trnbiếnđổi
=
snml
rjig
qfed
pcba
][T
28
Phép tnh tiến
[X'] = [ X ] . [ T(dx,dy,dz) ]
[ x' y' z' 1 ] =
[ x y z 1 ].[ T(dx,dy,dz) ]
z= [ x+dx y+dy z+dz 1 ]
=
1
0100
0010
0001
)],,([
dzdydx
dzdydxT
29
Phép tl
zs1, s2, s3 là các hstl
tương ng trên các trctođ
=
1000
0300
0020
0001
11 s
s
s
zyxzyx ][]'''[
]13.2.1.[ szsysx=
30
Rotation
zIn 2D, the only rotation possible was about the
origin.
zIn 3D, there are 3 possible rotations, one about
each of the x, y and z axes
zPositive rotations are anti-clockwise, negative
rotations are clockwise, when looking down a
positive axis towards the origin
x
y
z
x
y
z
x
y
z