天天看點

Games101筆記-Lecture03

Homogeneous Coordinates(齊次坐标)

在一個二維的空間中,對點做位移操作無法通過二維矩陣作用完成。是以用齊次坐标來完成對所有操作的表示。

齊次坐标中:

2D Point= ( x , y , 1 ) T (x, y,\textcolor{orange}1)^T (x,y,1)T 2D Vector= ( x , y , 0 ) T (x, y,\textcolor{orange}0)^T (x,y,0)T

對點進行位移操作:

( x ′ y ′ w ′ ) = ( 1 0 t x 0 1 t y 0 0 1 ) . ( x y 1 ) = ( x + t x y + t y 1 ) \begin{pmatrix}x^{'}\\y^{'}\\w^{'}\end{pmatrix}=\begin{pmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{pmatrix}.\begin{pmatrix}x\\y\\1\end{pmatrix}=\begin{pmatrix}x+t_x\\y+t_y\\1\end{pmatrix} ⎝⎛​x′y′w′​⎠⎞​=⎝⎛​100​010​tx​ty​1​⎠⎞​.⎝⎛​xy1​⎠⎞​=⎝⎛​x+tx​y+ty​1​⎠⎞​

w w w坐标為0或1的有效操作:

vector+vector = vector

vector+point = point

point - point = vector

point + point比較特殊, ( x y w ) \begin{pmatrix}x\\y\\w\end{pmatrix} ⎝⎛​xyw​⎠⎞​表示為一個2D Point ( x / w y / w 1 ) \begin{pmatrix}x/w\\y/w\\1\end{pmatrix} ⎝⎛​x/wy/w1​⎠⎞​,其中 w w w不為0

是以point + point = point(兩點的中點)

Affin Transformation仿射變換

( x ′ y ′ 1 ) = ( a b t x c d t y 0 0 1 ) . ( x y 1 ) \begin{pmatrix}x^{'}\\y^{'}\\1\end{pmatrix}=\begin{pmatrix}a&b&t_x\\c&d&t_y\\0&0&1\end{pmatrix}.\begin{pmatrix}x\\y\\1\end{pmatrix} ⎝⎛​x′y′1​⎠⎞​=⎝⎛​ac0​bd0​tx​ty​1​⎠⎞​.⎝⎛​xy1​⎠⎞​

Scale 放縮

S ( s x , s y ) = ( s x 0 0 0 s y 0 0 0 1 ) \bold{S}(s_x, s_y)=\begin{pmatrix}s_x&0&0\\0&s_y&0\\0&0&1\end{pmatrix} S(sx​,sy​)=⎝⎛​sx​00​0sy​0​001​⎠⎞​

Rotation 旋轉

R ( α ) = ( cos ⁡ α − sin ⁡ α 0 sin ⁡ α cos ⁡ α 0 0 0 1 ) \bold{R}(\alpha)=\begin{pmatrix}\cos{\alpha}&-\sin{\alpha}&0\\\sin{\alpha}&\cos{\alpha}&0\\0&0&1\end{pmatrix} R(α)=⎝⎛​cosαsinα0​−sinαcosα0​001​⎠⎞​

Translation 位移

T ( t x , t y ) = ( 1 0 t x 0 1 t y 0 0 1 ) \bold{T}(t_x, t_y)=\begin{pmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{pmatrix} T(tx​,ty​)=⎝⎛​100​010​tx​ty​1​⎠⎞​

一個矩陣的逆矩陣意味着進行逆操作,如順時針旋轉 α \alpha α為 R ( α ) \bold{R}(\alpha) R(α),則 R − 1 ( α ) \bold{R}^{-1}(\alpha) R−1(α)為逆時針旋轉 α \alpha α

Composing Transforms複合變換

變換是有順序的,即矩陣的作用順序不能随意改變。複雜的變換可以拆分成幾個基礎的變換矩陣的乘積。

如何表示繞某個點c旋轉?

可以先将點c移動到原點,進行旋轉,再移動回c。

T ( c ) ⋅ R ( α ) ⋅ T ( − c ) \bold{T}(c)\cdot\bold{R}(\alpha)\cdot\bold{T}(-c) T(c)⋅R(α)⋅T(−c)

3維空間中雷同

繼續閱讀