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 9 0
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

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

Thông tin tài liệu

– 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]

(1)

1

Bài 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: phép ánh xạtọađộ điểm hay

vector thành tọađộhay vector khác

modeling coordinateModeling

transformation Viewing transformation world

coordinate viewing coordinate(eye coordinate)

3

Phép biến đổi Transformations

zBiến đổi mơ hình hố - 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đổiAffine 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 hiệuứng cho tồnđối tượng.

–Ví dụ: phép biếnđổi tọađộvới chỉ2 điểmđầu cuối đoạn thẳng tạo thành điểm mà nối chúng với tạo thànhđoạn thẳng

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 với phép biến đổi thông qua phép nội suy

6

Modeling Transformations Transform

objects/points

(2)

7

Biu din Ma trn

zViệc biến đối đối tượng làm thay đổi điểm P thành đ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 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(Px,Py) = (Qx,Qy)

– 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, txand tylà 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

Q = + +

y y y

y cP dP t

Q = + +

Tr MP

Q= +

9

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

chiu

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 điểmảnh toàn đối tượng

⎥ ⎦ ⎤ ⎢ ⎣ ⎡ =

d c

b a T

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

ax d c

b a x T

X ⎥= + + =

⎦ ⎤ ⎢ ⎣ ⎡ = y

x z

pM

pW

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, Sxand Sy

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

T

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

0 *

*T x y a ax y x y

X ⎥= =

⎦ ⎤ ⎢ ⎣ ⎡ =

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

0 *

*T x y b bx dy x y

X ⎥= + =

⎦ ⎤ ⎢ ⎣ ⎡ =

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

Thuc tính cơ bn ca phép biến đổi AffineTransformations

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

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

zAffine transformations change volume by |

Det(M) |;

14

Kết hp 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

Thuc tính

z Tác động lên tập đ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

Đim gc - Pivotal points

Cho phép quay 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)

(0,0) 18

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

(4)

19

H tođộđồng nht

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

Tađộ đồng nht

Homogeneous Transform x' = ax + by + n

y' = cx + dy + m

zPhương pháp biu din mrng thông qua tađộ đồng nht ca vector vtrí zVing dng ca phép chiếu hình hc mà

đó tađộ đimđược mơ tdưới ma trn [ x* y* h]

vi x = x*/h, y = y*/h, z = z*/h h mt s

thc tuý

21

Ưuđim ca Htađộ đồng nht Homogeneous Transform

zÐưa nhìn hợp nhất của 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 phần mềm

zKết hợp các phép biếnđổi tạo thành ma trận

tíchđơn giản nhất Tránh nhầm lẫn vềthứtự

của phép nhân sửdụng.

– Order matters: ABis 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 vi tađộ đồng nht

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

zPhép tịnh tiến ⎥

⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ =

1 0 ]

[ n m

d c

b a T

] [

1

0 ] [ ] ' '

[ x m y n

n m y x y

x = + +

⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ =

(tx, ty, tz)

23

Phép tl

] [ 0

0

0 ] [ ] ' '

[ S xS yS

S y x y

x =

⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ =

24

Phép quay

y

(x, y )

x

α ρ

θ

ρ

( x’, y’ )

⎥ ⎥ ⎥ ⎦ ⎤ ⎢

⎢ ⎢ ⎣ ⎡ − =

1 0

0 cos sin

0 sin cos ] [ ] ' '

[ φ φ

φ φ y

x y x

] cos sin sin cos

[x φ−y φ x φ+y φ

(5)

25

Phép biếnđổi tng hp

26

Ma trn biến đổi chiu 3D Matrix Transformations

zCác phép biến đổi chuyển vị - translation, tỉ lệ

-scaling quay-rotation sử dụng không gian 2D đều co thể mở rộng 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 hc chiu z Biểu diễnđiểm không gian chiều

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

z[x' y' z' ]= [ x*/h y*/h z*/h ][ 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 tnh tiến

[X'] = [ X ] [ T(dx,dy,dz) ][ x' y' z' ] =

[ x y z ].[ T(dx,dy,dz) ]

z = [ x+dx y+dy z+dz ] ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢

⎢ ⎢ ⎢ ⎣ ⎡ =

1 0 1 0 0

0 0 1 0

0 0 0 1 )] , , ( [

dz dy dx dz dy dx T

29

Phép tl

zs1, s2, s3 hệsốtỉlệ

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

⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢

⎢ ⎢ ⎢ ⎣ ⎡ =

1 0

0 0

0

0 0 1

s s s z y x z y

x' ' ' ] [ ]

[

] 1 3 . 2 . 1 .

[x s y s z s =

30

Rotation

zIn 2D, the only rotation possible was about the

origin.

zIn 3D, there are 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

(6)

31

Phép quay chiu

zQuay quanh trục toạ độ

zQuay quanh trục x

zQuay quanh trục z

⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − = 0 0 0 0 0 φ φ φ φ cos sin sin cos ] [Tx ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − = 0 0 0 0 cos sin 0 sin cos ] [ ϕ ϕ ϕ ϕ Tz 32

Quay quanh trc y

⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − = 0 0 cos sin 0 0 sin cos ] [ θ θ θ θ Ty 33

Phép biến dng

(secondary translation) ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ = 0 0 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 lyđối xng

(reflections-secondary translation)

35

Quay quanh mt trc bt ksong song vi các trc tađộ

⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ = 0 0 0 0 0 ] [ z y Tr , ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − = 0 0 0 0 0 φ φ φ φ φ cos sin sin cos )] ( [T , ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − − = − 0 0 0 0 0 1 z y Tr] [ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ ⎡ − − + − − = sin ) cos ( sin ) cos ( 0 cos sin 0 sin cos 0 0 ] [ φ φ φ φ φ φ φ φ y z z y Tth 36

(7)

37

Solution

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

z Quay quanh trục y cho P1P2 nằm mặt phẳng (y, z)

z Quay quanh trục x cho P1P2 trùng với trục z z Quay quanh trục z cho P1P3 nằm 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

Ni 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

Htađthc

(WCS-World Coordinate System) z Là hệtọađộcủađối tượng

được chương trình

ứng dụng sửdụngđểmơ tảtọađộcủa cácđối tượng thếgiới thực

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

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

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

km

z Modeling Coordinate

41

Htađ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 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

Htađchun (NCS - Normalized Coordinate System)

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

zGiải quyết vấnđềkhiứng dụng chạy các

thiết bịkhác nhau

zCó kích thước 1x1

Wcs

chuyển đổi1

NCS Dcs

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