• 검색 결과가 없습니다.

Transformation Matrix

N/A
N/A
Protected

Academic year: 2021

Share "Transformation Matrix"

Copied!
37
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Transformation Matrix

Wanho Choi (wanochoi.com)

(2)

• 2D

• 3D

q(

x ,

y )

p(x, y)

q(

x ,

y ,

z )

p(x, y, z)

Transformation (

변환, 變換)

(3)

• 2D

• 3D

q(

x ,

y )

p(x, y)

q(

x ,

y ,

z )

p(x, y, z)

Transformation (

변환, 變換)

(4)

2D Scale

• About origin x− axis y− axis origin q(x ,y )p(x, y) x :x= 1:a y :y= 1:b

x

= ax

y

= by

(5)

• About origin θ

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin

(6)

• About origin θ

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin θ

(7)

• About origin θ x y θ

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin θ π 2−θ

(8)

• About origin θ θ x sinθ x cosθ x y

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin θ π 2−θ

(9)

• About origin θ θ x sinθ x cosθ y cosθ ysinθ x y

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin θ π 2−θ

(10)

• About origin θ θ x sinθ x cosθ y cosθ ysinθ x y

2D Rotation

p(x, y) q(x ,y )x− axis y− axis origin θ π 2−θ

x

= x cos

θ

− ysin

θ

y

= xsin

θ

+ ycos

θ

(11)

2D Translation

x

= x + dx

y

= y + dy

x− axis y− axis origin q(x ,y )p(x, y) dx dy

(12)

All Together

• 2D scale • 2D rotation • 2D translation ′ x = axy = byx = x cosθ − ysinθ ′ y = xsinθ + ycosθ ′ x = x + dxy = y + dy

(13)

As Matrices

• 2D scale • 2D rotation • 2D translation ′ x = axy = byx = x cosθ − ysinθ ′ y = xsinθ + ycosθ ′ x = x + dxy = y + dyxy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = a 00 b ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⎡ xy ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ xy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = cos θ −sinθ sinθ cosθ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⎡ xy ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ xy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = x y ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥+ dx dy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥

(14)

As Matrices

• 2D scale • 2D rotation • 2D translation ′ x = axy = byx = x cosθ − ysinθ ′ y = xsinθ + ycosθ ′ x = x + dxy = y + dyxy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = a 00 b ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⎡ xy ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ xy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = cos θ −sinθ sinθ cosθ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⎡ xy ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ xy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = x y ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥+ dx dy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ matrix × vector matrix × vector vector + vector

(15)

Simple Trick

• 2D scale • 2D rotation • 2D translation ′ x = axy = byx = x cosθ − ysinθ ′ y = xsinθ + ycosθ ′ x = x + dxy = y + dyxy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = a 0 0 0 b 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ′ xy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = cosθ −sinθ 0 sinθ cosθ 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ′ xy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = 1 0 dx 0 1 dy 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ matrix × vector matrix × vector matrix × vector

(16)

Transformation Matrices

• 2D scale • 2D rotation • 2D translation ′ x = axy = byx = x cosθ − ysinθ ′ y = xsinθ + ycosθ ′ x = x + dxy = y + dyxy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = a 0 0 0 b 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ′ xy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = cosθ −sinθ 0 sinθ cosθ 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ′ xy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = 1 0 dx 0 1 dy 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ q = Sp q = Rp q = Tp

(17)

Homogeneous Coordinate

• Introduced by August Ferdinand Möbius (1790~1868)

(a German mathematician and theoretical astronomer)

• A 2D point is represented by a 3D point.

• It has somewhat complex background, but you can

think that it is just a trick.

xy 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = e00 e01 e01 e10 e11 e12 e20 e21 e22 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ x y 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ x, y,1 ( ) → ′(x ,y ,1′ ) instead of x, y( ) → ′(x ,y′)

(18)

2D Point vs 2D Vector

• 2D point:

• When transforming a vector using transformation

matrices, we must not consider the translation.

• Therefore, 2D vector:

(x, y,1)

(x, y,0)

(0,0) (1,0) (0,1) dx = 1, dy = 1 (1,1) (2,1) (1,2) (0,1) right wrong

(19)

Addition/Subtraction of Point/Vector

• Vector + Vector = Vector (vector addition)

• Vector - Vector = Vector (vector subtraction)

Point + Point: undefined

Point - Point = Vector (displacement) • Point + Vector = Point (translation)

(20)

Addition/Subtraction of Point/Vector

• Vector + Vector = Vector (vector addition)

• Vector - Vector = Vector (vector subtraction)

Point + Point = Point (practically)Point - Point = Vector (displacement) • Point + Vector = Point (translation)

(21)

Position Vector (

위치 벡터)

• The addition of two points is not defined mathematically.

• But, we need this operation practically. (for example, the center of points)

• For solving this problem, we introduce the concept of “position vector”.

• A point is regarded as a vector (from the origin to the point position) temporarily for the computation.

c = p1 + p2 + p3 +!+ pn

(22)

Operating Order

• The result depends on the order of operations.

rotate translate

translate rotate

q = TRp

(23)

The Order of Operations

• The result depends on the order of operations.

But usually, scale → rotation → translation

TRSp ≠ TSRp ≠ SRTp ≠ RSTp ≠ ! Sp → R Sp

( )

→ T R Sp

(

( )

)

= TRSpx = ax cosθ − bysinθ + dxy = axsinθ + bycosθ + dy

(24)

• 2D

• 3D

q(

x ,

y )

p(x, y)

q(

x ,

y ,

z )

p(x, y, z)

Transformation (

변환, 變換)

(25)

3D Transformation

yz ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = cosβ −sinβ sinβ cosβ ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ y z ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ zx ⎡ ⎣ ⎢ ⎤ ⎦

⎥ = ⎡ cossinγγ −sincosγγ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ z x ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ ′ xy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ = cos α −sinα sinα cosα ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⎡ xy ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ′ xyz 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = a 0 0 0 0 b 0 0 0 0 c 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ x y z 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ′ xyz 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = 1 0 0 dx 0 1 0 dy 0 0 1 dz 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ x y z 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

(26)

3D Transformation

Rz(α) = cosα −sinα 0 0 sinα cosα 0 0 0 0 1 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ Rx(β) = 1 0 0 0 0 cosβ −sinβ 0 0 sinβ cosβ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ Ry(γ ) = cosγ 0 sinγ 0 0 1 0 0 −sinγ 0 cosγ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ S = a 0 0 0 0 b 0 0 0 0 c 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ T = 1 0 0 dx 0 1 0 dy 0 0 1 dz 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

(27)

Six Rotation Orders

• • • • • • RxRyRz RxRzRy RyRxRz RyRzRx RzRxRy RzRyRx Rz(γ )⋅ Ry(β)⋅ Rx(α)= cosγ 0 sinγ 0 0 1 0 0 −sinγ 0 cosγ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ 1 0 0 0 0 cosβ −sinβ 0 0 sinβ cosβ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ cosα −sinα 0 0 sinα cosα 0 0 0 0 1 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

(28)

Affine Transformation

• Translation, rotation, scaling, shear, and reflection

• It preserves parallelism, and ratios of distances between points lying on a straight line.

But, it does not necessarily preserve angles between

(29)

Affine Transformation

M =

m

00

m

01

m

02

m

03

m

10

m

11

m

12

m

13

m

20

m

21

m

22

m

23

m

30

m

31

m

32

m

33 0 1 translation

rotation and/or shear

(30)
(31)

Classes of Transformations

Rigid Transformation: distance preservingTranslation + Rotation

Similarity Transformation: angle preservingRigid + Isotropic Scale

Affine Transformation: line parallelism/ratio preservingSimilarity + Scale + Shear + Reflection

(32)

v: pivot point

M: transformation matrix

Transformation with a Pivot

(33)

1 0 pivot.x 0 1 pivot.y 0 0 1 ⎛ ⎝ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟ ⋅ cosθ −sinθ 0 sinθ cosθ 0 0 0 1 ⎛ ⎝ ⎜ ⎜⎜ ⎞ ⎠ ⎟ ⎟⎟⋅ 1 0 − pivot.x 0 1 − pivot.y 0 0 1 ⎛ ⎝ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟ = 1 0 pivot.x 0 1 pivot.y 0 0 1 ⎛ ⎝ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟⋅

cosθ −sinθ − pivot.x ⋅cosθ + pivot.y⋅sinθ sinθ cosθ − pivot.x ⋅sinθ − pivot.y⋅cosθ

0 0 1 ⎛ ⎝ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟ =

cosθ −sinθ − pivot.x ⋅cosθ + pivot.y⋅sinθ + pivot.x sinθ cosθ − pivot.x ⋅sinθ − pivot.y⋅cosθ + pivot.y

0 0 1 ⎛ ⎝ ⎜ ⎜ ⎜ ⎞ ⎠ ⎟ ⎟ ⎟ ≡ cosθ −sinθ tx sinθ cosθ ty 0 0 1 ⎛ ⎝ ⎜ ⎜⎜ ⎞ ⎠ ⎟ ⎟⎟ tx ty ⎛ ⎝

⎜ ⎞⎟ = ⎛ − pivot.x ⋅cos− pivot.x ⋅sinθθ− pivot.y⋅cos+ pivot.y⋅sinθθ + pivot.x+ pivot.y ⎝ ⎜ ⎞ ⎠ ⎟ = cosθ −sinθ sinθ cosθ ⎛ ⎝⎜ ⎞ ⎠⎟ − pivot.x − pivot.y ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ +⎛ pivot.xpivot.y ⎝ ⎜ ⎞ ⎠ ⎟

(34)

Column-Major vs Row-Major Vector

• Column-major vector • Row-major vector

p

c

=

[

x

y

z]

p

r

= [x y z]

3 × 1 1 × 3

p

c

= p

rT

q

c

= TRSp

c

q

r

= p

r

S

T

R

T

T

T

(35)

Column-Major vs Row-Major Vector

• Column-major vector • Row-major vector [x′ y′ z′] = [x y z] a d g b e h c f i = [ax + by + cz dx + ey + fz gx + hy + iz] x′ y′ z′ = a b c d e f g h i [ x y z] = ax + by + cz dx + ey + fz gx + hy + iz x′= ax + by + cz y′ = dx + ey + fz z′= gx + hy + iz

(36)

Column-Major vs Row-Major Matrix

• Column-major matrix • Row-major matrix

Maya, DirectX, PBRT, Zelos OpenGL, Eigen (default)

m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m0 m4 m8 m12 m1 m5 m9 m13 m2 m6 m10 m14 m3 m7 m11 m15

(37)

참조

관련 문서

–– 주 주 기능은 기능은 CPU CPU 내에 내에 있는 있는 회로로 회로로 기계어 기계어 명령을 명령을 해독하여 해독하여 필요핚 필요핚 제어 제어 싞호를.

"Beyond Computation: Information Technology, Organizational Transformation and Business Practices” shows the relationship between IT stock and productivity for a large sample

•• 비압축 비압축 디지털 디지털 오디오 오디오//비디오 비디오 데이터를 데이터를 젂송하기 젂송하기 위핚 위핚 소형 소형

The informative Annex A to this International Standard gives additional information intended to assist understanding and use of the document; it does not itself constitute part

The language of the journey is used as indicative of the reality that transformation and achievement of equality and justice are actually a process not necessarily a once

: Model Parallelism in Deep Learning is NOT What You Think : Paper, Efficient and Robust Parallel DNN Training through Model Parallelism on Multi-GPU Platfrom,

It would be reasonable as a teacher to make efforts not only to reflect on the class on their own, but also to improve the teacher's teaching expertise

Note (i): It is recommended that, for Road Races staged over standard distances, the start and finish points, measured along a theoretical straight line between them