現(xiàn)代計算機圖形學(xué)入門-閆令琪-01

前言:一些讀書筆記
引用閆令琪老師的課程內(nèi)容,GAMES101,老師講的很好,可以看原課程視頻。

Overview of Computer Graphics

基本就是介紹這門課,然后講了一下學(xué)習(xí)的意義和學(xué)習(xí)所需的前置知識和工具等。
1)什么是計算機圖形學(xué)?
使用計算機合成和操作視覺信息。
2)課程內(nèi)容
Rasterization 光柵化
Curves and Meshes 曲線和網(wǎng)格
Ray Tracing 光學(xué)追蹤
Animation/Simulation 動畫/仿真
3)作業(yè)鏈接地址
http://games-cn.org/forums/topic/allhw/

Review of Linear Algebra

基本就是線代的一些基礎(chǔ)知識,其中怎樣將這些知識應(yīng)用于實際會讓人更好的理解線代在CG上的應(yīng)用。
1)Vectors
向量(數(shù)學(xué)上),矢量(物理上)。
Dot product:a·b=||a||||b||\cos{\theta}
作用:
1.判斷2個方向之間的距離
2.分解1個向量
3.判斷前后dot product > or < 0
Cross product:axb=||a||||b||\sin{\theta}
作用:
1.判斷左側(cè)/右側(cè)
例如:當(dāng)叉乘方向為正時,b在左側(cè)


2.判斷內(nèi)側(cè)/外側(cè)
例如:求ABxAP,P在AB左側(cè);求BCxBP,P在BC左側(cè);求CAxCP,P在CA左側(cè)。于是P在內(nèi)側(cè),否則會存在異側(cè)的情況。

2)Matrices

Transformation

這節(jié)課主要講了一些圖形變化時,計算機所做的變化。
1)2D變換
主要用矩陣
1.scale 縮放(縮寫0.5倍時)
\left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \left[ \begin{matrix} s & 0\\ 0 & s \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right],s=0.5


2.reflection 反射(關(guān)于y軸鏡像)
\left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \left[ \begin{matrix} -1 & 0\\ 0 & 1 \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right]

3.shear 切變(水平方向移動a
\left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \left[ \begin{matrix} 1 & a\\ 0 & 1 \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right]

4.rotate 旋轉(zhuǎn)(旋轉(zhuǎn)\theta
\left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \left[ \begin{matrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right]

2)齊次坐標(biāo)
1.平移不能用之前x'=Mx矩陣形式表示,即,平移不是線性變化
2.解決辦法:增加一個維度
2D point = (x,y,1)^T
2D vector = (x,y,0)^T,向量有平移不變性
此時平移操作為:
\left[ \begin{matrix} x' \\ y' \\w' \end{matrix} \right] = \left[ \begin{matrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} x \\ y \\ 1\end{matrix} \right]
一般操作:
vector + vector = vector
point - point = vector
point + vector = point
point + point = 中點 (\left[ \begin{matrix} x \\ y \\w \end{matrix} \right] \rightarrow \left[ \begin{matrix} x/w \\ y/w \\ 1 \end{matrix} \right]
3.總結(jié):仿射變換Affine Transformations
Affine map = linear map + transformation
\left[ \begin{matrix} x' \\ y' \end{matrix} \right] = \left[ \begin{matrix} a & b\\ c & d \end{matrix} \right] \left[ \begin{matrix} x \\ y \end{matrix} \right] + \left[ \begin{matrix} t_x \\ t_y \end{matrix} \right]
Using homogenous coordinates
\left[ \begin{matrix} x' \\ y' \\ 1\end{matrix} \right] = \left[ \begin{matrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} x \\ y \\ 1\end{matrix} \right]

3)3D變換
與2D變換類似,多了一維。
1.齊次坐標(biāo)
3D point = (x,y,z,1)^T
3D vector = (x,y,z,0)^T
實際上,3D point是用(x,y,z,w)表示(x/w,y/w,z/w)。
2.先線性變換,后平移
3.旋轉(zhuǎn)操作:以某個軸為基準(zhǔn)旋轉(zhuǎn)(這種方法的可行性可以從飛機的直觀例子得到)
R_x(\alpha) = \left[ \begin{matrix} 1 & 0 & 0 & 0 \\ 0 & \cos{\alpha} & -\sin{\alpha} & 0 \\ 0 & \sin{\alpha} & \cos{\alpha} & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right]

R_y(\alpha) = \left[ \begin{matrix} \cos{\alpha} & 0 & \sin{\alpha} & 0 \\ 0 & 1 & 0 & 0 \\ -\sin{\alpha} & 0 & \cos{\alpha} & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right]

R_z(\alpha) = \left[ \begin{matrix} \cos{\alpha} & -\sin{\alpha} & 0 & 0 \\ \sin{\alpha} & \cos{\alpha} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right]

可以將一個任意旋轉(zhuǎn)拆分為在各個軸方面的旋轉(zhuǎn)的組合。

Rodrigues' Rotation Formula:
n軸旋轉(zhuǎn)\alpha度,其中這個n向量默認(rèn)會平移到原地再開始旋轉(zhuǎn)。
R(n,\alpha) = \cos{(\alpha)}I+(1-\cos{(\alpha)})nn^T+\sin{(\alpha)}\left[ \begin{matrix} 0 & -n_z & n_y \\ n_z & 0 & -n_x \\ -n_y & n_x & 0 \end{matrix} \right]

4)view transformation
1.拍照過程可以解釋為如下過程:
找好地方,聚集好人(model transformation)
找好角度(viewing transformation)
茄子(projection transformation)
2.定義相機
位置向量e
往哪看\hat{g}
向上\hat{t}
3.初始相機放在原點,上到Y(jié),看向-Z(Mview)
如果相機和物體一起運動,那么它們是相對靜止的,為了能識別物體的運動,我們默認(rèn)相機是靜止的,且有個初始狀態(tài)。
這期間需要做的操作有:1、將e水平移到原點,旋轉(zhuǎn)g到-Z,旋轉(zhuǎn)t到Y(jié),旋轉(zhuǎn)gxt到X,即Mview = RviewTview。
其中Tview = \left[ \begin{matrix}1 & 0 & 0 & -x_e \\ 0 & 1 & 0 & -y_e \\ 0 & 0 & 1 & -z_e \\ 0 & 0 & 0 & 1 \end{matrix} \right]
因為直接去求Rview不好求,我們使用逆向思維去求-Z到g,Y到t,X到gxt。
可以得到Rview^(-1) = \left[ \begin{matrix} x_{\hat{g}\times\hat{t}} & x_t & x_{-g} & 0 \\ y_{\hat{g}\times\hat{t}} & y_t & y_{-g} & 0 \\ z_{\hat{g}\times\hat{t}} & z_t & z_{-g} & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right]
舉例:Rview^(-1)·X = Rview^(-1)·\left[ \begin{matrix} 1 \\ 0 \\0 \\0 \end{matrix} \right]=\left[ \begin{matrix} x_{\hat{g}\times\hat{t}} \\ y_{\hat{g}\times\hat{t}} \\z_{\hat{g}\times\hat{t}} \\0 \end{matrix} \right] = \hat{g}\times\hat{t}
因為旋轉(zhuǎn)矩陣是正交矩陣,于是就得到Rview = \left[ \begin{matrix} x_{\hat{g}\times\hat{t}} & y_{\hat{g}\times\hat{t}} & z_{\hat{g}\times\hat{t}} & 0\\ x_t & y_t & z_t & 0 \\ x_{-g} & y_{-g} & z_{-g} & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right]
5)投影變換 projection transformation
正交投影 orthographic projection
透視投影 perspective projection


1.正交投影
一種說法:照相機初始化,扔掉Z坐標(biāo),縮放到[-1,1]^2
另一種說法:平移、縮放為標(biāo)準(zhǔn)塊,map[l,r]x[b,t]x[f,n] to cube [-1,1]^3
這里是l,r對應(yīng)左右,b,t對應(yīng)下上,f,n對應(yīng)遠近,因為是指向-Z的右手系,遠的反而是小的。
Mortho = \left[ \begin{matrix} \frac{2}{r-l} & 0 & 0 & 0 \\ 0 & \frac{2}{t-b} & 0 & 0 \\ 0 & 0 & \frac{2}{n-f} & 0 \\ 0 & 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 & -\frac{r+l}{2} \\ 0 & 1 & 0 & -\frac{t+b}{2} \\ 0 & 0 & 1 & -\frac{n+f}{2} \\ 0 & 0 & 0 & 1 \end{matrix} \right]
Mortho先平移到原點,然后進行縮放。
2.透視投影
透視投影是遠的東西會變小,那么我們期望下面的左子圖能變成右子圖Mpersp->ortho,再進行正交投影Mortho。這樣就完成了透視投影。具體怎樣得到Mpersp->ortho的過程比較復(fù)雜??偟膩碚f就是一個相似三角形的定理,然后根據(jù)定義中遠的矩陣會縮成近的,中心點不變,遠近不變等等條件做插值求得矩陣。

Mpersp->ortho = \left[ \begin{matrix} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ 0 & 0 & n+f & -nf \\ 0 & 0 & 1 & 0 \\\end{matrix} \right]
注意,有時候也可以用fovY和Aspect ratio來表示t,b,l,r。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容