Mathematics for 3d graphics

44
Mathematics for 3D Graphics 3Dグラフィックスのための数学

description

Was used at Kosen Conference in Kinki.

Transcript of Mathematics for 3d graphics

Page 1: Mathematics for 3d graphics

Mathematics for 3D Graphics

3Dグラフィックスのための数学

Page 2: Mathematics for 3d graphics

自己紹介@a3geek (ID変えました)

「アーさん」です !

チームラボ (teamLab Inc.) Interaction Engineer

!

福井高専自主卒業組 数学は苦手です

Page 3: Mathematics for 3d graphics

こんな人のために(3Dで使う数学って難しそう……)

(っていうか数学って難しそう……)

( ˘ω˘)

( ˘ω˘)

(っていうか数学苦手だから無理)( ˘ω˘)

Page 4: Mathematics for 3d graphics

数学むずかしい!

Page 5: Mathematics for 3d graphics

使うだけなら 難しくない!!

\こわくないよ/

Page 6: Mathematics for 3d graphics

座標とベクトル

マトリクスと計算

Page 7: Mathematics for 3d graphics

座標とベクトルの違い

(x1, y1, z1,w1)

(x2, y2, z2,w2)

Page 8: Mathematics for 3d graphics

x

Y

Z

座標1 (x, y, z, 1)

座標2 (x+a, y+b, z+c, 1+0)

ベクトル (a, b, c, 0)

Page 9: Mathematics for 3d graphics

座標=

位置情報ベクトル=

方向情報

Page 10: Mathematics for 3d graphics

x

Y

Z

座標1 (x, y, z, 1)

座標2 (x+a, y+b, z+c, 1+0)

ベクトル (a, b, c, 0)

座標1をベクトルの方向に移動したら座標2

Page 11: Mathematics for 3d graphics

データ的には 違いがない

Page 12: Mathematics for 3d graphics

(x, y, z, w)

であらわす!

座標とベクトルは両方共

Page 13: Mathematics for 3d graphics

ん?

Page 14: Mathematics for 3d graphics

w?

Page 15: Mathematics for 3d graphics

wって大事?

Page 16: Mathematics for 3d graphics

とても大事

Page 17: Mathematics for 3d graphics

座標はw=1

ベクトルはw=0

しかもwの値は決まっている

Page 18: Mathematics for 3d graphics

マトリクスが

それを知るには

必要になる

Page 19: Mathematics for 3d graphics

マトリクスって?

Page 20: Mathematics for 3d graphics

マトリクスとは

座標やベクトルを変換するのに必要なもの

(行列とも言う)

Page 21: Mathematics for 3d graphics

X Y Z W

a e i

m

d h l p

c g k o

b f j n

X’ Y’ Z’ W’

座標 or ベクトル行列変換された

座標 or ベクトル

Page 22: Mathematics for 3d graphics

行列

X Y Z Wa e i

m

d h l p

c g k o

b f j n

X’ = X * a + Y * b + Z * c + W * d掛けあわせて加算

X Y Z W

X’ Y’ Z’ W’

座標 or ベクトル変換された

座標 or ベクトル

Page 23: Mathematics for 3d graphics

変換には何があるの?

拡大縮小

回転

平行移動

Page 24: Mathematics for 3d graphics

変換行列は決まってる

Page 25: Mathematics for 3d graphics

変換には何があるの?

拡大縮小

回転

平行移動

Page 26: Mathematics for 3d graphics

Sx 0 0 0

0 0 0 1

0 0 Sz 0

0 Sy 0 0

Sx、Sy、SzはそれぞれX軸、Y軸、Z軸に対する倍率

Page 27: Mathematics for 3d graphics

X Y Z W

Sx 0 0 0

0 0 0 1

0 0 Sz 0

0 Sy 0 0

X * Sx Y * Sy Z * Sz

W

拡大縮小行列 座標 or ベクトル倍率が変化した

座標 or ベクトル

Page 28: Mathematics for 3d graphics

変換には何があるの?

拡大縮小

回転

平行移動

Page 29: Mathematics for 3d graphics

Y軸に対する回転

X軸に対する回転

1 0 0 0

0 0 0 1

0 -sinθx cosθx

0

0 cosθx sinθx

0

cosθy 0

-sinθy 0

0 0 0 1

sinθy 0

cosθy 0

1 0 0 0

(θxはX軸に対する回転量)

(θyはY軸に対する回転量)

Z軸に対する回転

cosθz sinθz

0 0

0 0 0 1

1 0 0 0

-sinθz cosθz

0 0(θzはZ軸に対する回転量)

Page 30: Mathematics for 3d graphics

変換には何があるの?

拡大縮小

回転

平行移動

Page 31: Mathematics for 3d graphics

1 0 0 0

Px Py Pz 1

0 0 1 0

0 1 0 0

Px、Py、PzはそれぞれX軸、Y軸、Z軸に対する移動量

Page 32: Mathematics for 3d graphics

X Y Z W

1 0 0 0

Px Py Pz 1

0 0 1 0

0 1 0 0

X + Px * W Y + Py * W Z + Pz * W

W

平行移動行列 座標 or ベクトル平行移動した

座標 or ベクトル

Page 33: Mathematics for 3d graphics

?!

Page 34: Mathematics for 3d graphics

X Y Z W

1 0 0 0

Px Py Pz 1

0 0 1 0

0 1 0 0

X + Px * W Y + Py * W Z + Pz * W

W

平行移動行列 座標 or ベクトル平行移動した

座標 or ベクトル

Page 35: Mathematics for 3d graphics

w!

Page 36: Mathematics for 3d graphics

wの必要性

Page 37: Mathematics for 3d graphics

w要素によって

座標とベクトルの 性質の違いによる問題を解決する

Page 38: Mathematics for 3d graphics

性質の違い?

拡大縮小 回転 平行移動

座標 ○ ○ ○

ベクトル ○ ○ ×

Page 39: Mathematics for 3d graphics

ベクトルは方向を表しているため 実体が存在しない

平行移動の影響を受けない

Page 40: Mathematics for 3d graphics

座標の時

ベクトルの時w = 1

w = 0

Page 41: Mathematics for 3d graphics

X Y Z 1

1 0 0 0

Px Py Pz 1

0 0 1 0

0 1 0 0

X + Px * 1 Y + Py * 1 Z + Pz * 1

W

W=1の時は平行移動する → 座標

W=0の時は平行移動しない → ベクトル

X Y Z 0

1 0 0 0

Px Py Pz 1

0 0 1 0

0 1 0 0

X + Px * 0 Y + Py * 0 Z + Pz * 0

W

Page 42: Mathematics for 3d graphics

平行移動における矛盾 を解消する!

Page 43: Mathematics for 3d graphics

wって大事!

Page 44: Mathematics for 3d graphics

数学むずかしくない!\こわくないよ/