2012年2月7日 星期二

Shadow Matrix 筆記

尋找如何做出 Shadow matrix 的過程中,發現 HOTBALL'S HIVE 介紹得很好。但是
有些推導過程,中間的步驟很簡明,對於新手的我來說,還是得拿紙筆來演練,
才能順利接上,在此作個筆記。為了一致性,這裡的符號標示,也是沿用該網頁。

目的:給定光源,在已知平面上 (以 normal vector \( \vec P \) 表示)找出平面以外某一點 \( \vec V \),
在平面上的投影點,然後導出其 Matrix Operation。


如圖,沿著射線,存在ㄧ k 值,使得 \( \vec V \) + k\( \vec L \) 為平面上的交點:
\[ (\vec V + k \vec L) \cdot \vec P = 0 \] \[ k = -\frac{\vec V \cdot \vec P}{\vec L \cdot \vec P} \] 所以投影點為: \[ \begin{align} \vec V + k \vec L &= \vec V - \frac{\vec V \cdot \vec P}{\vec L \cdot \vec P} \vec L \cr &= \frac{\vec V (\vec L \cdot \vec P) - (\vec V \cdot \vec P) \vec L}{\vec L \cdot \vec P} &(\ddagger) \end{align} \] 令 \[ \begin{align} \vec L &= \langle L_x,L_y,L_z,0 \rangle \cr \vec V &= \langle V_x,V_y,V_z,1 \rangle \cr \vec P &= \langle a,b,c,d \rangle \end{align} \] 對於 homogeneous coordinate \( \langle x,y,z,w \rangle \) 而言,w 是分母之意, 亦即對應的 3D coordinate 為 \( \langle x/w, y/w, z/w \rangle \), 也就是 \( \vec L \cdot \vec P \) 在 homogeneous coordinate 表示下恰為 \( w \) 之值。 展開 \((\ddagger)\) 式子的分子為: \[ \langle V_x,V_y,V_z,1 \rangle (aL_x + bL_y + cL_z) - (aV_x + bV_y + cV_z + d) \langle L_x,L_y,L_z,0 \rangle \] 其中 \(x\) 分量為: \[ V_x(bL_y + cL_z) - V_y(bL_x) - V_z(cL_x) - dL_x \] 同法可得 \(y,z\) 分量,整理得到 shadow matrix: \[ \begin{bmatrix} bL_y + cL_z & -bL_x & -cL_x & -dL_x \cr -aL_y & aL_x + cL_z & -cL_y & -dL_y \cr -aL_z & -bL_z & aL_x + bL_y & -dL_z \cr 0 & 0 & 0 & aL_x + bL_y + cL_z \end{bmatrix} \] 內心獨白: \(\LaTeX\) 打了會上癮!

MathJax Test

This is a test of using MathJax in Blogger   Note that enclosing math in single $'s does not work in the default setting for MathJax.  However, you may use "\(\backslash(\)" and "\(\backslash)\)" for inline math and double dollar signs or "\(\backslash[\)" and "\(\backslash]\)" for displayed math.  Examples for inline is:  \( (y+\sqrt z)^{-1} \) and  \( \sin^2 x^2 \).  And, a displayed equation is: $$\frac 2 3$$
Another displayed equation is here:
\[
\forall x \exists y (x\le y \land y\le x \leftrightarrow x=y) .
\]
\[
\vec \Phi ( \vec r) = -\frac{G M_1}{| \vec{r}-\vec r_1 |} \]

To setup the MathJax capability, I added the following line to the HTML code, after the <head> command (as a single line, no line break):

<script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>

You can find more information from the MathJax website about this at http://www.mathjax.org/docs/1.1/start.html.