1. Trang chủ
  2. » Địa lí lớp 10

Bài giảng môn Đồ họa và hiện thực ảo - Bài 4: Các phép biến đổi đồ hoạ - Transformations

7 11 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 448,51 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

– 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 tr[r]

Trang 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 kỹ thuật đồ hoạ 3 bước: Mô hình, Tô trát

và Hiên thị (modeling, rendering, displaying)

zVới Modeling ( Mô hình hóa) :

zTransformation: 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

zBiến đổi mô hình hoá - Modeling transformations

– build complex models by positioning simple

components

zBiến đổi tạo 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 đổ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

zCá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

Trang 2

Biểu diễn Ma trận

zViệ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

zViệc biến đổi P sử dụng tọa độ của P (Px,Py) ánh

xạ thành các tọa độ mới Q (Qx,Qy)

zViệ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

z 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ố

z Biểu diễn ma trận:

z i.e ⎜⎜⎛ ⎟⎟⎞=⎜⎜⎛ ⎟⎟⎞⎜⎜⎛ ⎟⎟⎞+⎜⎜⎛ ⎟⎟⎞

y x y x y

x

t t P P d c b a Q Q

x x x

x aP bP t

y y y

y cP dP t

Tr MP

9

Các phép biến đổi hình học hai

chiều

z Phương pháp biểu diễn đối tượng P = [ x y ]

z Phép biến đổi vị trí điểm

z 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

=

d c b a T

[ ] [ ] [* y]* [ (ax cy) ( bx dy) ] [x' y']

d c b a x T

y

x z

pM

10

Phép biến đổi

z Phép bất biến

z Phép biến đổi tỉ lệ - Scaling

z A scaling changes the size of an object with two scale

factors, S x and S y

z Phép biến dạng

z A shearing shears an object in a particular direction, (in 2D, it’s either in the x or in the y direction

= 1 0 0 1

T

[ ] [ ] [ ] [ ( ) ] [' ']

1 0

0

*

[ ] [ ] [ ] [ ] [' ']

1 0

1

*

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’ )

=

θ θ θ θ cos sin sin cos ]

[T

12

Thuộc tính cơ bản của 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;

Trang 3

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-mid-points

zAffine transformations change volume by |

Det(M) |;

14

Kết hợp các phép biến đổi Composition of Affine Transforms

z Any affine transformation can be decomposed into elementary transformations

z 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

z It is rare that we want to perform just one elementary

transformation

z 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

z These individual transformations combine into one

overall transformation

z This is called the composition of transformations

z The composition of two or more affine transformations

is also an affine transformation

16

Thuộc tính

z 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

z We have defined each transformation by their effects on single points

z 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

z The simple versions of rotation and scaling have been based around the

origin.

z This means that when we rotate or scale, the object will also move, with

respect to the origin

z Translate all points through (-c1,-c2)

z Rotate all points about the origin by

z Translate all points back through (c1,c2)

(c1,c2)

Pivotal points

z Often we wish to rotate or scale with respect to some pivotal point, not the origin

z Most significantly, we often wish to rotate or scale an object about its centre, or midpoint

z In this way, the object’s location does not change

z 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

Trang 4

Hệ toạ độ đồng nhất

zVấn đề gặp phải:

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

Tọa độ đồng nhất Homogeneous Transform

x' = ax + by + n

y' = cx + dy + m

zPhươ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í

zVớ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

zÐư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

zKế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

zCho 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

zMa trận biến đổi đồng nhất

= 1 0

0 ]

[

n m d c b a T

] 1 [

1 0 1 0 0 0 1 ] 1 [ ] 1 ' '

n m y x y

=

(t x , t y , t z )

23

Phép tỉ lệ

] 1 2 1 1 0 0 0 2 0 0 0 1 ] 1 [ ]

1

'

'

S y x y

=

24

Phép quay

y

( x, y )

x

α

ρ

θ

ρ

( x’, y’ )

=

1 0 0

0 cos sin

0 sin cos ] 1 [ ] 1 ' '

φ φ

y x y x

] 1 cos sin sin cos

=

Trang 5

Phép biến đổi tổng hợp

26

Ma trận biến đổi 3 chiều 3D Matrix Transformations

zCác phép biến đổi chuyển vị - translation, tỉ lệ-scaling và quay-rotation sử dụng trong không gian 2D đều co thể mở rộng 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 đổi hình học 3 chiều

z Biểu diễn điểm trong không gian 3 chiều

z[ x* y* z* h ] = [ x y z 1 ] [ T ]

z[x' y' z' 1 ]= [ x*/h y*/h z*/h 1 ][ T ]

z Ma trận biến đổi

=

s n m l

r j i g

q f e d

p c b a ]

[T

28

Phép tịnh 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 0 1 0 0

0 0 1 0

0 0 0 1 )]

, , ( [

dz dy dx

dz dy dx T

29

Phép tỉ lệ

z s1, s2, s3 là các hệ số tỉ lệ

tương ứng trên các trục toạ độ

=

1 0 0 0

0 3 0 0

0 0 2 0

0 0 0 1 1 1

s s s z y x z

y

x' ' ' ] [ ]

[

] 1 3 2 1

.

=

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

Trang 6

Phép quay 3 chiều

zQuay quanh các trục toạ độ

z Quay quanh trục x

z Quay quanh trục z

=

1 0 0 0

0 0

0 0

0 0 0 1

φ φ φ φ cos sin sin cos ]

[Tx

=

1 0 0 0

0 1 0 0

0 0 cos sin

0 0 sin cos ]

ϕ ϕ

Tz

32

Quay quanh trục y

=

1 0 0 0

0 cos 0 sin

0 0 1 0

0 sin 0 cos ] [

θ θ

θ θ

Ty

33

Phép biến dạng

(secondary translation)

=

1 0 0 0

0 1 0 1 0 1

1 1

i g f d c b z

y x z y

x' ' ' ] [ ]

[

] 1 [ x + yd + gz bx + y + iz cx + fy + z

=

34

Phép lấy đối xứng ( reflections-secondary translation)

35

Quay quanh một trục bất kỳ song song với

các trục tọa độ

=

1 0

0 1 0

0

0 0 1

0

0 0 0

1

]

[

z y

Tr

=

1 0 0 0

0 0

0 0

0 0 0 1

φ φ φ φ φ

cos sin sin cos )]

(

[T

,

=

1 0

0 1 0 0

0 0 1 0

0 0 0 1 1

z y

Tr]

[

− +

=

1 sin ) cos 1 ( sin )

cos

1

(

0

0 cos sin

0

0 sin cos

0

0 0 0

1

]

[

φ φ φ φ

φ φ

φ φ

y z z y

Tth

36 Quay quanh một trục bất kỳ

Trang 7

Solution

z Chuyển P1 về gốc tọa độ

z Quay quanh trục y sao cho P1P2 nằm trờn mặt phẳng

(y, z)

z Quay quanh trục x sao cho P1P2 trựng với trục z

z Quay quanh trục z sao cho P1P3 nằm trờn mặt phẳng

(y, z)

z Euler’s Theorem: Every rotation around the origin

can be decomposed into a rotation around the x-axis

followed by a rotation around the y-axis followed by a

rotation around the z-axis.

38

Biến đổi gúc nhỡn Viewing Transformation

Lờ Tấn Hựng

39

Nội dung

zPhộp biến đổi nhỡn cơ bản

zBiến đổi hệ thống tọa độ

zCamera

zBiến đổi 3D viewing

zVớ dụ

40

Hệ tọa độ thực (WCS-World Coordinate System)

z Là hệ tọa độ của đối tượng được cỏc chương trỡnh ứng dụng sử dụng để mụ

tả tọa độ của cỏc đối tượng trong thế giới thực

z Đơn vị trong hệ thống tọa

độ phụ thuộc vào khụng gian và kớch thước của đối tượng được mụ tả, cú thể

từ A0, nm, mm đến m,

km

z Modeling Coordinate

41

Hệ tọa độ thiết bị

(DCS-Device Coordinate System)

zLà hệ thống tọa độ của thiết bị nơi hiển thị

hỡnh ảnh và khụng gian của đối tượng mà

ứng dụng mụ tả

Thiết bị hiển thị

subselect.me

Vùng tọa độ thiết bị VGA=640x480

42

Hệ tọa độ chuẩn (NCS - Normalized Coordinate System)

zChuyển đổi hệ tọa độ

zGiải quyết vấn đề khi ứng dụng chạy trờn cỏc thiết bị khỏc nhau

zCú kớch thước 1x1

Wcs

chuyển đổi 1

NCS Dcs

chuyển đổi 2

Ngày đăng: 09/03/2021, 04:04

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm