View
39
Download
1
Category
Preview:
Citation preview
1
(c) SE/FIT/HUT 2002 1
Bài 4B:Phép biến đổi trong không gian
(c) SE/FIT/HUT 2002 2
Ma trận biến đổi 3 chiều 3D Matrix Transformations
Cá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 3DAgain, using homogeneous coordinates it is possible to represent each type of transformation in a matrix formIn 3D, each transformation is represented by a 4x4 matrix
(c) SE/FIT/HUT 2002 3
Các phép biến đổi hình học 3 chiềuBiểu diễn điểm trong không gian 3 chiều
• [ x* y* z* h ] = [ x y z 1 ]. [ T ]• [x' y' z' 1 ]= [ x*/h y*/h z*/h 1 ][ T ]
Ma trận biến đổi
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
snmlrjigqfedpcba
][T
(c) SE/FIT/HUT 2002 4
Phép tịnh tiến
[X'] = [ X ] . [ T(dx,dy,dz) ][ x' y' z' 1 ] = [ x y z 1 ].[ T(dx,dy,dz) ]
= [ x+dx y+dy z+dz 1 ]
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
1010000100001
)],,([
dzdydx
dzdydxT
(c) SE/FIT/HUT 2002 5
Phép tỉ lệ
• s1, s2, s3 là các hệ số tỉ lệ tương ứngtrên các trục toạ độ
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
1000030000200001
11s
ss
zyxzyx ][]'''[
]13.2.1.[ szsysx=
(c) SE/FIT/HUT 2002 6
RotationIn 2D, the only rotation possible was about the origin.In 3D, there are 3 possible rotations, one about each of the x, y and z axesPositive rotations are anti-clockwise, negative rotations are clockwise, when looking down a positive axis towards the origin
x
y
zx
y
z
x
y
z
2
(c) SE/FIT/HUT 2002 7
Phép quay 3 chiều
Quay quanh các trục toạ độ• Quay quanh trục x
• Quay quanh trục z
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−=
100000000001
φφφφ
cossinsincos
][Tx
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡−
=
1000010000cossin00sincos
][ϕϕϕϕ
Tz
(c) SE/FIT/HUT 2002 8
Quay quanh trục y
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡ −
=
10000cos0sin00100sin0cos
][θθ
θθ
Ty
(c) SE/FIT/HUT 2002 9
Phép biến dạng(secondary translation)
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
1000010101
11ig
fdcb
zyxzyx ][]'''[
]1[ zfycxizybxgzydx ++++++=
(c) SE/FIT/HUT 2002 10
Phép lấy đối xứng(reflections-secondary translation)
(c) SE/FIT/HUT 2002 11
Quay quanh một trục bất kỳ song song với cáctrục tọa độ
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
10010000100001
][
zy
Tr
, ⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−=
100000000001
φφφφ
φcossinsincos
)]([T
,
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−−
=−
10010000100001
1
zy
Tr][
⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢
⎣
⎡
−−+−−
=
1sin)cos1(sin)cos1(00cossin00sincos00001
][
φφφφφφφφ
yzzy
Tth
(c) SE/FIT/HUT 2002 12
Quay quanh một trục bất kỳ
3
(c) SE/FIT/HUT 2002 13
SolutionChuyển P1 về gốc tọa độ.Quay quanh trục y sao cho P1P2 nằm trên mặt phẳng (y, z)Quay quanh trục x sao cho P1P2 trùng với trục z.Quay quanh trục z sao cho P1P3 nằm trên mặt phẳng (y, 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.
(c) SE/FIT/HUT 2002 14
Bước 1: Chuyển P1 về gốc tọa độ
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−−−
=−−−
1111010000100001
111
zyx
zyxT )],,([
y
P3
P2P1
z x
y
P3
P2 p P1z
x
(c) SE/FIT/HUT 2002 15
Bước 2: Quay quanh trục y
cos( - 90 + φ) = sinφ = z'2/L = ( z2 - z1)/Lsin( - 90 + φ) = - cosφ = x'2/L = ( x2 - x1)/L
[ P''2 ] = [ P'2 ][ T(φ-90) ]= [ 0 y2-y1 L ]
y
P3
P'2(x'2,y'2,z'2)
P'1L φ
z(x'2,0,z'2)x
212
212
22
22 )()()'()'( xxzzxzL −−==
(c) SE/FIT/HUT 2002 16
Bước 3: Quay quanh trục x.
cos ϕ = z''2/N, sin ϕ = y''2/N
Với N = | P''1P''2| là độ dài của đoạn P''1P''2
[P'''2] = [P''2][T(ϕ)] = [P'2][T(φ-90)][T(ϕ)]
= [P2 ][T(-x1,-y1,-z1 ][T(φ-90)][T(ϕ)]
= [ 0 0 |P1P2| 1 ]
y
P''2N
P''1ϕ
x
z
(c) SE/FIT/HUT 2002 17
Bước 4: Quay quanh trục z
[P'''3]= [P3 ][T(-x1,-y1,-z1 ][T(φ-90)][T(ϕ)]
Với góc quay dương ψ trên trục z cos ψ = y3
'''/M; sin ψ = x3'''/M;
Ma trận tổng hợp của các phép biến đổi [ T ] códạng sau đáp ứng toàn bộ quá trình biến đổi quay đối tượng quanh một trục bất kỳ.[ T ] = [T(-x1,-y1,-z1)][T(φ-90)][T(ϕ)][T(ψ)]
yy'''3
P'''3ψ
Mx'''3
P'''2P'''1x
z
(c) SE/FIT/HUT 2002 18
Kết quả sau biến đổi cần phải đưa về vị trí ban đầu qua các phép biến đổingược.
[Tth]= [T(-x1,-y1,-z1)]x[T(φ-0)]x[T(ϕ)]x [T(ψ)]x[T(ψ)]x[T(ϕ)]x[T(φ-90)]x[T(-x1,-y1,-z1)]
4
(c) SE/FIT/HUT 2002 19
Hệ toạ độCoordinate Frame
Coordinate frame is given by origin φ and three mutually orthogonal unit vectors, i, j, k.Mutually orthogonal (dot products): i•j = ?; i•k = ?; j•k = ?.Unit vectors (dot products): i•i = ?; j•j = ?; k•k = ?.
xz
yi
j
k
φ
(c) SE/FIT/HUT 2002 20
Orientation
xz
yi
j
k
φ
Right handed coordinate system: Left handed coordinate system:
Cross product: i x j = ?
xz
yi
jk
φ
Cross product: i x j = ?
(c) SE/FIT/HUT 2002 21
Coordinate Transformations
xz
yi
j
k
φ
Transform (x, y, z, 0) coordinate frame to (i, j, k, φ) coordinate frame.
Affine transformation matrix:
Maps (i, j, k, φ) coordinates into (x, y, z, 0) coordinates!
.
1000 ⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
φφφ
zzzz
yyyy
xxxx
kjikjikji
(c) SE/FIT/HUT 2002 22
Coordinate change (Translation)
(φx, φy, φz)
.
110001 ⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
cba
zyx
xz
y
a
c
b
(0,0,0)
Change from (a,b,c,φ) coordinates to (x,y,z,0) coordinates:
(c) SE/FIT/HUT 2002 23
Coordinate change (Rotation)
.
110001 ⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
cba
zyx
c
(φx, φy, φz)a
b
(0,0,0)
Change from (a,b,c,φ) coordinates to (x,y,z,0) coordinates:
y x
z
θ
(c) SE/FIT/HUT 2002 24
Composition of coordinate change
zφ
x
y
M1 changes from coordinate frame (x,y,z,θ) to (x’,y’,z’,θ’).M2 changes from coordinate frame (x’,y’,z’,θ’) to (x’’,y’’,z’’,θ’’).Change from coordinate frame (x,y,z,θ) to (x’’,y’’,z’’,θ’’): ?
z’φ’ x’
y’
z’’φ’’
x’’
y’’
M1
M2
5
(c) SE/FIT/HUT 2002 25
Object vs. coordinate transformationsTranslate and then rotate object:
Translate and then rotate coordinate frame:z
φx
y
zφ
x
y
zφ
x
y
zφ
x
y
zφ
x
y
z’φ’
x’
y’
zφ
x
y
z’’φ’’ x’’
y’’
(c) SE/FIT/HUT 2002 26
Object vs. coordinate transformations (2)Translate and then rotate object:
Rotate and then translate coordinate frame:z
φx
y
zφ
x
y
zφ
x
y
zφ
x
y
zφ
x
y
zφ
x
y
z’’φ’’ x’’
y’’
z’φ’
x’
y’
(c) SE/FIT/HUT 2002 27
Order of transformations
Let Mi be the transformation matrix for transformation Ti.
Sequence of object (point) transformations, T1, T2, T3.Transformation matrix = M3 x M2 x M1.
Sequence of coordinate system transformations, T1, T2, T3.Transformation matrix = M1 x M2 x M3.
Note: OpenGL, OpenInventor use coordinate system transformations.
(c) SE/FIT/HUT 2002 28
Hệ tọa độ thực(WCS-World Coordinate System)
Là hệ tọa độ của đối tượngđược các chương trình ứngdụng sử dụng để mô tả tọa độcủa các đối tượng trong thế giớithực. Đơ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 đượcmô tả, có thể từ A0, nm, mm ... đến m, km ...
(c) SE/FIT/HUT 2002 29
Hệ tọa độ thiết bị(DCS-Device Coordinate System)
Là hệ thống tọa độ của thiết bị nơi hiển thị hình ảnh và khônggian 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
(c) SE/FIT/HUT 2002 30
Hệ tọa độ chuẩn(NCS - Normalized Coordinate System)
Giải quyết vấn đề khi ứng dụng chạy trên các thiết bị khácnhauCó kích thước 1x1
WcschuyÓn ®æi 1
NCS DcschuyÓn ®æi 2
6
(c) SE/FIT/HUT 2002 31
Display Co-ordinatesThe integer, (x, y) screen co-ordinates are far too restrictive to be used to describe physical objects and scenes, because:
objects and scenes would need to be remodelled for every new view, or if the device resolution is changedThe range of coordinate values (e.g: 640x480, 1024x768 pixels) is inappropriate for many scenes
(c) SE/FIT/HUT 2002 32
MODELLING Co-ordinatesMore logical to use dimensions which are appropriate to the object. e.g.
metres for buildings, millimetres for assembly parts, nanometres or microns for molecules, cells, and atoms
Objects are described with respect to their actual physical size in the real world, These measurements are then mapped onto screen co-ordinatesbefore displaying
(c) SE/FIT/HUT 2002 33
Basic Viewing TransformApply transform to convert from Modelling co-ordinates to Screen CoordinatesWe can scale dimensions to change the resulting viewWe can even achieve a zooming in and out effect without changing the model by scaling dimensions proportionallyVấn đề:How much of the model should be drawn?Where should it appear on the display?How do we convert Real-world co-ordinates into screen co-ordinates?
(c) SE/FIT/HUT 2002 34
2-Dimensional ViewsA 2-dimensional view consists of two rectangles:
A Window given in real world co-ordinates, defining the portion of model (scene) to be drawnA Viewport given in screen co-ordinates, defining the portion of the screen which will be used to display the contents of the window
(wxmin,wymin)
(wxmax,wymax)
(vxmin,vymin)
(vxmax,vymax)
(wx,wy) (vx,vy)
(c) SE/FIT/HUT 2002 35
Phép chuyển đổi
(c) SE/FIT/HUT 2002 36
Phép biến đổi theo ma trậnMa trận chuyển vị theo Window
Ma trận biến đổi tỉ lệ
Ma trận chuyển vị theo tọa độ viewport
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
−−=
1010001
1YwXw
T ][
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−−
=
100
0minmaxminmax0
00Xwmin-XwmaxXvmin-Xvmax
]1[YwYwYvYvS
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
1010001
]2[YyXv
T
7
(c) SE/FIT/HUT 2002 37
Ma trận biến đổi tổng hợp của phép chuyển đổitọa độ
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−−
−−
−−
=
=
1minmaxminmaxminmin
Xwmin-XwmaxXvmin-Xvmaxminmin
0minmaxminmax0
00Xwmin-XwmaxXvmin-Xvmax
][
]2[]1[]1[][
YwYwYvYvYwYvXwXv
YwYwYvYvT
TxSxTT
(c) SE/FIT/HUT 2002 38
Ánh xạ cửa sổ trên tới màn hình 640x480 viewport
-0.4 -0.2
0.3
0.4
480
640
(c) SE/FIT/HUT 2002 39
Bài tập
Wx=-.2Wy=.3Wxmax=0Wxmin=-0.4Wymax=0.4Wymin=0
Vx= (-.2-(-0.4))*(640-0) + 0 = 3200-(-0.4)
Vy= (.3-0)*(0-480) + 480 = 1200-(-0.4)
Vxmax=640Vxmin=-0.4Vymax=0Vymin=480
320
120
Recommended