Professional Documents
Culture Documents
Ma Tran Bien Doi
Ma Tran Bien Doi
Bài 4B:
3D Matrix Transformations
Phép biến đổi trong không gian
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 3D
Again, using homogeneous coordinates it is possible to
represent each type of transformation in a matrix form
In 3D, each transformation is represented by a 4x4 matrix
Các phép biến đổi hình học 3 chiều Phép tịnh tiến
Biểu diễn điểm trong không gian 3 chiều
• [ x* y* z* h ] = [ x y z 1 ]. [ T ] ⎡1 0 0 0⎤
• [x' y' z' 1 ]= [ x*/h y*/h z*/h 1 ][ T ] ⎢0 1 0 0⎥⎥
[T (dx, dy, dz )] = ⎢
Ma trận biến đổi
⎡a b c p ⎤ ⎢0 0 1 0⎥
⎢d e f q ⎥ ⎢ ⎥
⎣dx dy dz 1⎦
[T ] = ⎢ ⎥
⎢g i j r ⎥ [X'] = [ X ] . [ T(dx,dy,dz) ]
⎢ ⎥ [ x' y' z' 1 ] =
⎣l m n s⎦ [ x y z 1 ].[ T(dx,dy,dz) ]
= [ x+dx y+dy z+dz 1 ]
Phép tỉ lệ Rotation
⎡ s1 0 0 0⎤
In 2D, the only rotation possible was about the origin.
⎢ 0 s2 0 0⎥⎥ In 3D, there are 3 possible rotations, one about each of the x,
z 1] ⎢
[ x' y ' z ' 1] = [ x y y and z axes
⎢ 0 0 s3 0⎥
⎢ ⎥ Positive rotations are anti-clockwise, negative rotations are
⎣0 0 0 1⎦ clockwise, when looking down a positive axis towards the
= [x .s 1 y .s 2 z .s 3 1] origin
y y y
• s1, s2, s3 là các hệ số tỉ lệ tương ứng
trên các trục toạ độ x x
x
z z z
(c) SE/FIT/HUT 2002 5 (c) SE/FIT/HUT 2002 6
1
Phép quay 3 chiều Quay quanh trục y
Quay quanh các trục toạ độ ⎡cos θ 0 − sin θ 0⎤
⎢ 0 1 0 0⎥
• Quay quanh trục x
⎡1 0 0 0⎤ [Ty ] = ⎢ ⎥
⎢0 cos φ ⎢ sin θ 0 cos θ 0⎥
sin φ 0⎥⎥ ⎢ ⎥
[Tx ] = ⎢ ⎣ 0 0 0 1⎦
⎢0 − sin φ cos φ 0⎥
⎢ ⎥
⎣0 0 0 1⎦
• Quay quanh trục z
⎡ cos ϕ sin ϕ 0 0⎤
⎢ − sin ϕ cos ϕ 0 0⎥⎥
[Tz ] = ⎢
⎢ 0 0 1 0⎥
⎢ ⎥
⎣ 0 0 0 1⎦
⎡ 1 b c 0⎤
⎢ d 1 f 0⎥
[ x' y ' z ' 1] = [ x y z 1] ⎢ ⎥
⎢ g i 1 0⎥
⎢ ⎥
⎣ 0 0 0 1⎦
= [x + yd + gz bx + y + iz cx + fy + z 1]
Quay quanh một trục bất kỳ song song với các Quay quanh một trục bất kỳ
trục tọa độ
⎡1 0 0 0⎤ ⎡1 0 0 0⎤
⎢0 ⎢0 cos φ 0⎥⎥
1 0 0⎥ sin φ
[ Tr ] = ⎢ ⎥ [T (φ )] = ⎢
⎢0 0 1 0⎥ ⎢0 − sin φ cos φ 0⎥
, ⎢ ⎥ ⎢ ⎥
, ⎣0 y z 1⎦ ⎣0 0 0 1⎦
⎡1 0 0 0⎤ ⎡1 0 0 0⎤
⎢ ⎥ ⎢0 1
[Tth]=⎢
0 cosφ sinφ 0⎥ 0 0⎥⎥
⎢0 −sinφ cosφ 0⎥ [Tr] −1
=⎢
⎢0 0 1 0⎥
⎢ ⎥ ⎢ ⎥
⎢⎣0 y(1−cosφ)+zsinφ z(1−cosφ)−ysinφ 1⎥⎦
⎣0 − y − z 1⎦
2
Solution Bước 1: Chuyển P1 về gốc tọa độ
z-axis.
L = (z'2 ) 2
(x'2 ) = (z2 − z1 )
2 2
(x2 − x1 ) 2
P''2
P3 N
P''1
ϕ
[P'''2] = [P''2][T(ϕ)] = [P'2][T(φ-90)][T(ϕ)]
[ P''2 ] = [ P'2 ][ T(φ-90) ] x
P'2(x'2,y'2,z'2)
= [ 0 y2-y1 L ] = [P2 ][T(-x1,-y1,-z1 ][T(φ-90)][T(ϕ)] z
P'1
L φ = [ 0 0 |P1P2| 1 ]
z(x'2,0,z'2)x
(c) SE/FIT/HUT 2002 15 (c) SE/FIT/HUT 2002 16
P'''2P'''1
x
z
3
Hệ toạ độ
Coordinate Frame Orientation
Right handed coordinate system: Left handed coordinate system:
y
j
φ i k
y y
j j
φ i i
k
φ
z x k
Coordinate frame is given by origin φ and three mutually orthogonal unit vectors, z x z x
i, j, k.
Mutually orthogonal (dot products): i•j = ?; i•k = ?; j•k = ?.
Unit vectors (dot products): i•i = ?; j•j = ?; k•k = ?. Cross product: i x j = ? Cross product: i x j = ?
b
y x y’
M2
y φ’’
θ z’’
(φx, φy, φz) M1
x’’
(0,0,0) a φ’ x’
c z’
z φ
z x
Change from (a,b,c,φ) coordinates to ⎛ x⎞ ⎡ ⎤⎛ a ⎞
⎜ ⎟ ⎢ ⎥⎜ b ⎟
⎜ y⎟ ⎢ M1 changes from coordinate frame (x,y,z,θ) to (x’,y’,z’,θ’).
(x,y,z,0) coordinates:
= ⎥ ⎜ ⎟.
⎜ z⎟ ⎢ ⎥⎜ c ⎟
M2 changes from coordinate frame (x’,y’,z’,θ’) to (x’’,y’’,z’’,θ’’).
4
Object vs. coordinate transformations Object vs. coordinate transformations (2)
Translate and then rotate object: Translate and then rotate object:
y y y y y y
φ φ φ φ φ φ
z x z x z x z x z x z x
Translate and then rotate coordinate frame: Rotate and then translate coordinate frame:
y’’
y y y’ y
y y’’ y’y y
x’’
φ’’
φ φ φ’ x’’ φ φ x’
x
φ φ’’ x
φ z ’’
z z z’ x x’ z z φ’ x
z x z’ z x
z’’
(c) SE/FIT/HUT 2002 25 (c) SE/FIT/HUT 2002 26
Hệ tọa độ thực
Order of transformations (WCS-World Coordinate System)
Let Mi be the transformation matrix for transformation Ti.
Là hệ tọa độ của đối tượng
Sequence of object (point) transformations, T1, T2, T3. được các chương trình ứng
Transformation matrix = M3 x M2 x M1.
dụng sử dụng để mô tả tọa độ
của các đối tượng trong thế giới
thực.
Sequence of coordinate system transformations, T1, T2, T3. Đơn vị trong hệ thống tọa độ
Transformation matrix = M1 x M2 x M3. phụ thuộc vào không gian và
kích thước của đối tượng được
Note: OpenGL, OpenInventor use coordinate system transformations. mô tả, có thể từ A0, nm, mm ...
đến m, km ...
Là hệ thống tọa độ của thiết bị nơi hiển thị hình ảnh và không Giải quyết vấn đề khi ứng dụng chạy trên các thiết bị khác
gian của đối tượng mà ứng dụng mô tả. nhau
Có kích thước 1x1
subselect.me
NCS Dcs
Wcs chuyÓn ®æi 2
Vïng täa ®é thiÕt bÞ chuyÓn ®æi 1
VGA=640x480
5
Display Co-ordinates MODELLING Co-ordinates
The integer, (x, y) screen co-ordinates are far too restrictive to be More logical to use dimensions which are appropriate to the
used to describe physical objects and scenes, because: object. e.g.
objects and scenes would need to be remodelled for every new view, or if metres for buildings,
the device resolution is changed millimetres for assembly parts,
The range of coordinate values (e.g: 640x480, 1024x768 pixels) is nanometres or microns for molecules, cells, and atoms
inappropriate for many scenes
Objects are described with respect to their actual physical size in
the real world,
These measurements are then mapped onto screen co-ordinates
before displaying
⎡ Xvmax- Xvmin ⎤
⎢ Xwmax- Xwmin 0 0⎥
Ma trận biến đổi tỉ lệ ⎢ Yv max− Yv min ⎥
[S1] = ⎢ 0 0⎥
⎢ Yw max− Yw min ⎥
⎢ 0 0 1⎥
⎣⎢ ⎥⎦
⎡1 0 0⎤
Ma trận chuyển vị theo tọa độ viewport [T 2] = ⎢⎢ 0 1 0⎥⎥
⎢⎣ Xv Yy 1 ⎥⎦
6
Ma trận biến đổi tổng hợp của phép chuyển đổi
tọa độ
0.4
0.3
[T ] = [T1]x[S1]x[T 2]
⎡ Xvmax- Xvmin ⎤
⎢ 0 0⎥
Xwmax- Xwmin -0.4 -0.2
⎢ Yv max− Yv min ⎥
[T ] = ⎢ 0 0⎥
⎢ Ywmax− Ywmin ⎥ Ánh xạ cửa sổ trên tới màn
⎢ Xv min− Xwmin Xvmax- Xvmin Yv min− Ywmin Yv max− Yv min 1⎥ hình 640x480 viewport
⎣⎢ Xwmax- Xwmin Ywmax− Ywmin ⎦⎥ 480
640
(c) SE/FIT/HUT 2002 37 (c) SE/FIT/HUT 2002 38
Bài tập
Wx=-.2 Vxmax=640
Wy=.3
Wxmax=0 Vxmin=-0.4
Wxmin=-0.4 Vymax=0
Wymax=0.4 Vymin=480
Wymin=0