Tải bản đầy đủ (.pdf) (94 trang)

Giáo trình thực tại ảo BKHN lesion 5:Các phép biến đổi Đồ hoạ Transformations

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.81 MB, 94 trang )

1
Bài 4 Các phép biến đổi Đồ hoạ
Transformations
Le Tan Hung
Email:
2
Phép biến đổi - Transformations
 Trong kỹ thuật đồ hoạ 3 bước: Mô hình, Tô trát
và Hiên thị (modeling, rendering, displaying)
 Với Modeling ( Mô hình hóa) :




 Transformation: là phép ánh xạ tọa độ điểm hay
vector thành tọa độ hay vector khác
modeling
coordinate
Modeling
transformation
Viewing
transformation
world
coordinate
viewing
coordinate
(eye
coordinate)
3
Phép biến đổi Transformations
 Biến đổi mô hình hoá - Modeling transformations


– build complex models by positioning simple
components
 Biến đổi tạo góc nhìn - Viewing transformations
– placing virtual camera in the world
– transformation from world coordinates to camera
coordinates
 Biến Phép chiếu – Projection Transform
4
Transformations - Modeling
world
5
Phép biến đổi Affine
Affine Transformations?
 Phép biến đổi Affine là phép biến đổi tọa độ
điểm đặc trưng của đối tượng thành tập tương
ứng các điểm mới để tạo ra các hiệu ứng cho
toàn đối tượng.
– Ví dụ: phép biến đổi tọa độ với chỉ 2 điểm đầu cuối của
đoạn thẳng tạo thành 2 điểm mới mà khi nối chúng với
nhau tạo thành đoạn thẳng mới.
 Các điểm nằm trên đoạn thẳng sẽ có kết quả là
điểm nằm trên đoạn thẳng mới với cùng phép biến
đổi thông qua phép nội suy.
6
Modeling Transformations
Transform
objects/points
Transform coordinate system
7
Biểu diễn Ma trận

 Việc biến đối các đối tượng làm thay đổi các
điểm P thành các điểm Q theo thuật toán
 Việc biến đổi P sử dụng tọa độ của P (P
x
,P
y
) ánh
xạ thành các tọa độ mới Q (Q
x
,Q
y
)
 Việc biến đổi có thể biểu diễn thông qua hàm T,
hàm ánh xạ của điểm:
– T(P
x
,P
y
) = (Q
x
,Q
y
)
– or:
– T(P) = Q
8
Matrix Representation
 Phép biến đổi đồ họa - affine transformation T ánh xạ
tập P sang tập Q:




– where a, b, c, d, tx and ty là các hệ số
 Biểu diễn ma trận:


 i.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 đổi hình học hai
chiều
 Phương pháp biểu diễn đối tượng P = [ x y ]
 Phép biến đổi vị trí điểm

 Thực thi phép biến đổi đúng trên 1 điểm ảnh sẽ đúng
trên toàn bộ đối tượng







dc
ba
T
     
   
 
 
''
y dybx *y * xcyax
dc
ba
xTX 








y

x

z

p
M

p
W
10
Phép biến đổi
 Phép bất biến

 Phép biến đổi tỉ lệ - Scaling
 A scaling changes the size of an object with two scale
factors, S
x
and S
y


 Phép biến dạng
 A 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
Thuộc tính cơ bản của phép biến
đổi Affine Transformations
 Preservation 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;

13
Thuộc tính
 Preservation of parallelism
– Preservation of parallelism guarantees that
parallelograms will transform into parallelograms
 Preservation of proportional distances
– Preservation of proportional distances means that mid-
points of lines remain mid-points
 Affine transformations change volume by |
Det(M) |;


14
Kết hợp các phép biến đổi
Composition of Affine Transforms
 Any affine transformation can be
decomposed into elementary
transformations.
 Mọi phép biến đổi phức tạp đều
có thể tạo thành từ các phép biến
đổi cơ sở như:
– Dịch chuyển - Translation
– Tỉ lệ - Scaling
– Quay- Rotation
– Biến dạng - Shearing
15
Affine transformations preserve
affine combinations
 It is rare that we want to perform just one elementary
transformation.

 Usually 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
 These individual transformations combine into one
overall transformation
 This is called the composition of transformations.
 The composition of two or more affine transformations
is also an affine transformation
16
Thuộc tính
 Tác động lên tập các điểm đặc trưng của đối
tượng tạo thành phép biến đổi cho đối tượng
 We have defined each transformation by their effects on
single points
 In practice these will be applied to multiple points to
transfer entire scenes or objects made up of many
defining points
T
17
Điểm gốc - Pivotal points
Cho phép quay và tỉ lệ Rotation and Scaling
 The simple versions of rotation and scaling have been based around the
origin.
 This means that when we rotate or scale, the object will also move, with
respect to the origin
 Translate all points through (-c1,-c2)
 Rotate all points about the origin by
 Translate all points back through (c1,c2)


(c
1
,c
2
)
(0,0)
18
Pivotal points
 Often we wish to rotate or scale with respect to some
pivotal point, not the origin
 Most significantly, we often wish to rotate or scale an
object about its centre, or midpoint
 In this way, the object’s location does not change
 To 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
19
Hệ toạ độ đồng nhất

 Vấn đề gặp phải:
 An affine transformation is composed of a linear
transformation followed by a translation
 Unfortunately, the translation portion is not a
matrix multiplication but must instead be added as
an extra term, or vector
 What we need is a “trick”, so that translations can

be represented in matrix multiplication form
 This then means that they can be easily
composed with other transformations, by simply
multiplying the matrices together
20
Tọa độ đồng nhất
Homogeneous Transform
– x' = ax + by + n
– y' = cx + dy + m
 Phương pháp biểu diễn mở rộng thông qua
tọa độ đồng nhất của các vector vị trí

 Với ứng dụng của phép chiếu hình học mà
ở đó tọa độ điểm được mô tả dưới ma trận [
x* y* h]
– với x = x*/h, y = y*/h, z = z*/h và h là một số
thực tuỳ ý
21
Ưu điểm của Hệ tọa độ đồng nhất
Homogeneous Transform
 Ðưa ra cái nhìn hợp nhất của các phép biến đổi
dưới phép nhân ma trận, hỗ trợ cho việc xử lý
bằng cả phần cứng và phần mềm
 Kết hợp các các phép biến đổi tạo thành ma trận
tích đơn giản duy nhất. Tránh nhầm lẫn về thứ tự
của các phép nhân khi sử dụng.
– Order matters: AB is generally not the same as BA
 Cho phép kết hợp với cả các phép biến đổi đặc
biệt không tuyến tính khác(non-affine) như:
– Phép chiếu phối cảnh - Perspective projections!

– Uốn - Bends, Vuốt tapers v.v.v
22
Phép biến đổi với tọa độ đồng nhất
 Ma trận biến đổi đồng nhất

 Phép tịnh tiến















1
0
0
][
nm
dc
ba
T
]1[

1
010
001
]1[]1''[ nymx
nm
yxyx 











(t
x
, t
y
, t
z
)
23
Phép tỉ lệ
]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 
25
Phép biến đổi tổng hợp

×