# Linear Transformations ## Basics - Coordinate System - Translation - Scaling - Rotation ## Coordinate Systems - Cartesian Coordinate System (x, y) - Polar Coordinate System ($\theta$ + reference direction) ### Skewed Space When a space is skewed, all stuff is skewed, including light and it's projections. ### 2D $$ \hat{i} = \pmatrix{1\\0}, \hat{j} = \pmatrix{0\\1} $$ $$ \begin{array}l (x, y) &= x\hat{i} + y\hat{j}\\ &= x\pmatrix{1\\0} + y\pmatrix{0\\1}\\ &= \pmatrix{x\\y} \end{array} $$ ### Different Ways to see (x,y) Re-define the (x,y) coordinate. - x, y as scalar of $\hat{i},\hat{j}$ - x, y as the projected vectors on $\hat{i},\hat{j}$ ### 3D $$ \hat{i} = \pmatrix{1\\0\\0}, \hat{j} = \pmatrix{0\\1\\0}, \hat{k} = \pmatrix{0\\0\\1} $$ $$ \begin{array}l (x, y, z) &= x\hat{i} + y\hat{j} + z\hat{k}\\ &= x\pmatrix{1\\0\\0} + y\pmatrix{0\\1\\0} + z\pmatrix{0\\0\\1}\\ &= \pmatrix{x\\y\\z} \end{array} $$ ### Projections - Othgonal Projection - Perspective Projection ## Translation $$ \cases{ x' = x + \Delta x\\ y' = y + \Delta y\\ z' = z + \Delta z\\ } \implies (x',y',z') = (x+\Delta x, y+\Delta y, z+\Delta z) $$ $$ \begin{array}l \pmatrix{x'\\y'\\z'} &= \pmatrix{x\\y\\z}+\pmatrix{\Delta x\\\Delta y\\\Delta z}\\ &=\pmatrix{x+\Delta x\\y+\Delta y\\ z+\Delta z} \end{array} $$ ## Scaling - Scale $\hat{i}$ $x\hat{i} \implies x\hat{i'}$ - Scale $\hat{j}$ $y\hat{j} \implies y\hat{j'}$ - Scale $\hat{k}$ $z\hat{k} \implies z\hat{k'}$ ## Rotation - $\pm 90^\circ$ - $\pm \theta$ ## Relection ### Conjugate #### 2D Reflection - Reflection to $\hat{i}\implies\cases{\hat{i}\implies\hat{i}\\\hat{j} \implies -\hat{j}}$ - Reflection to $\hat{j}\implies\cases{\hat{i}\implies -\hat{i}\\\hat{j} \implies \hat{j}}$ - 2D Reflection to $y=x\implies f(x,y)=(y,x)$ - 2D Reflection to $y=-x\implies f(x,y)=(-y,-x)$ - Reflection to a vector(u,v) #### 3D Reflection - Reflection to $\hat{i}\implies\cases{\hat{i}\implies\hat{i}\\\hat{j} \implies -\hat{j}\\\hat{k} \implies -\hat{k}}$ - Reflection to $\hat{j}\implies\cases{\hat{i}\implies -\hat{i}\\\hat{j} \implies \hat{j}\\\hat{k} \implies -\hat{k}}$ - Reflection to $\hat{k}\implies\cases{\hat{i}\implies -\hat{i}\\\hat{j} \implies -\hat{j}\\\hat{k} \implies \hat{k}}$ - Reflection to a vector (Quat) ## Coordinate Transformation $$ \cases{ (x,y)\text{ in coordinate system A}\\ (x',y')\text{ in coordinate system B } } $$ ### Example World Coordinate(Space) to Camera Coordinate(Space) Model coordinate $(x, y, z)$ in world space. Camera coordinate $(cam_x, cam_y, cam_z)$ in world space. #### Model coordinate relative to Camera coodinrate $$ \pmatrix{x'\\y'\\z'\\1}= \pmatrix{1&0&0&-cam_x\\ 0&1&0&-cam_y\\ 0&0&1&-cam_z\\ 0&0&0&1 }\pmatrix{x\\y\\z\\1} $$ #### Transform to Carmera's Viewport(Space) Camera's right: $\vec{u}$ = $(u_x, u_y, u_z)$ Camera's up: $\vec{v}$ = $(v_x, v_y, v_z)$ Camera's back: $\vec n$ = $(n_x, n_y, n_z)$, where $-\vec{n}$ is the direction to the target(lookAt) $$ \pmatrix{ u_x&v_x&n_x&0\\ u_y&v_x&n_y&0\\ u_z&v_z&n_z&0\\ 0&0&0&1 }^{-1} = \pmatrix{ u_x&u_y&u_z&0\\ v_x&v_y&v_z&0\\ n_x&n_y&n_z&0\\ 0&0&0&1 } $$ $$ \pmatrix{x''\\y''\\z''\\1}= \pmatrix{ u_x&u_y&u_z&0\\ v_x&v_y&v_z&0\\ n_x&n_y&n_z&0\\ 0&0&0&1 } \pmatrix{x'\\y'\\z'\\1} $$ ###### tags: `math` `geometry` `linear transformation`