ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

(GAMES101) 1 - Review && Transformation (2D)

2022-07-27 00:36:05  阅读:169  来源: 互联网

标签:begin end Vert Review 2D vec bmatrix mathbf GAMES101


「転科・転専攻」は失敗したが、
千束ちゃんは「やりたいこと最優先!」と言ってくれました!

 

#1. Review of Linear Algebra

Vectors Normalization & Cartesian Coordinates

magnitude (length) : \(\Vert\vec a\Vert\)

unit vector : \(\hat a = \cfrac{\vec a}{\Vert {\vec a} \Vert}\)

\(\boldsymbol A = \begin{bmatrix} ~x~ \\ y \end{bmatrix} ~~~~~ \boldsymbol A^T = \begin{bmatrix} ~x , ~y~ \end{bmatrix} ~~~~~ \Vert \boldsymbol A \Vert = \sqrt{x^2 + y^2}\)

Dot (Scalar) Product

\(\vec a \cdot \vec b = \Vert \vec a \Vert \Vert \vec b \Vert \cos \theta ~~~~~ \cos \theta = \cfrac{\vec a \cdot \vec b}{\Vert \vec a \Vert \Vert \vec b \Vert}\)

for unit vectors : \(\cos \theta = \hat a \cdot \hat b\)

in cartesian coordinates : \(\vec a \cdot \vec b = \begin{bmatrix} ~x_a~ \\ y_a \\ z_a \end{bmatrix} \cdot \begin{bmatrix} ~x_b~ \\ y_b \\ z_b \end{bmatrix} = x_ax_b + y_ay_b + z_az_b\)

\[i.e. ~~\boldsymbol a \cdot \boldsymbol b = \boldsymbol a ^ T \boldsymbol b \]

projection of \(\vec b\) onto \(\vec a\) : \(\Vert\vec b_{\perp}\Vert = \Vert \vec b \Vert \cos \theta\)

usage : intersection angle, decompose, determine for/backward

Cross (Vector) Product

construct coordinate systems

cartesian formula : \(\vec a \times \vec b = \begin{bmatrix} ~y_az_b - y_bz_a ~\\~ z_ax_b - x_az_b ~\\~ x_ay_b - y_ax_b ~\end{bmatrix}\)

\[i.e. ~~ \vec a \times \vec b = A^*\boldsymbol b = \mathop{\begin{bmatrix} ~ 0 & -z_a & y_a ~\\ ~z_a & 0 & -x_a~ \\ ~-y_a & x_a & 0~\end{bmatrix}}\limits_{\text{dual matrix of a}} \begin{bmatrix} ~x_b~ \\ ~y_b~ \\ ~0~\end{bmatrix} \]

usage : determine left / right, determine inside / outside

Matrix

array of numbers ($m \times n = $ m rows, n columns)

Matrix-Matrix Multiplication

require # columns in A = # rows in B

\[i.e. ~~(m \times n)(n \times p) = (m \times p) \]

\((i, j)\) is dot product of \(\mathcal{row~ i~ from~ A}\) and \(\mathcal{column~ j~ from~ B}\)

  • non-commutative (\(AB\) and \(BA\) are different in general)

  • associative and distributive :

\[(AB)C = A(BC) \\ A(B + C) = AB + AC \\ (A + B)C = AC + BC \]

Matrix-Vector Multiplication

treat vector as a column matrix \(m \times 1\)

key for transforming points

Transpose of a Matrix

switch rows and columns

property : \((AB)^T = B^TA^T\)

Identity Matrix and Inverses

\(AA^{-1} = A^{-1}A = I ~~~~~~~~~ (AB)^{-1} = B^{-1}A^{-1}\)

 

 

#2. Transformation (2D)

Scaling

\[\begin{bmatrix}~ x' ~\\~ y' ~\end{bmatrix} = \begin{bmatrix} ~s_x & 0 ~\\~ 0 & s_y ~\end{bmatrix} \begin{bmatrix}~ x ~\\ ~ y ~ \end{bmatrix} \]

Reflection

horizontal reflection

\[\begin{bmatrix}~ x' ~\\ y'\end{bmatrix} = \begin{bmatrix} ~-1 & 0 ~ \\~ 0 & 1~\end{bmatrix} \begin{bmatrix} ~x~ \\ y\end{bmatrix} \]

Shearing

horizontal shift

\[\begin{bmatrix}~ x' ~\\ y'\end{bmatrix} = \begin{bmatrix} ~1 & \tan\phi ~ \\~ 0 & 1~\end{bmatrix} \begin{bmatrix} ~x~ \\ y\end{bmatrix} \]

Rotation

about the origin \((0,0)\), CCW by default

\[\begin{bmatrix}~ x' ~\\ y'\end{bmatrix} = \begin{bmatrix} ~\cos\phi & -\sin\phi ~ \\~ \sin\phi & \cos\phi \end{bmatrix} \begin{bmatrix} ~x~ \\ y\end{bmatrix} \]

Linear Transforms = Matrices (of the same dimension)

\[\mathbf x' = \mathcal M \mathbf x \]

Translation

In order to solve such the problem

\[\begin{bmatrix} ~ x' ~ \\ ~ y' ~ \end{bmatrix} = \mathcal M \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ \end{bmatrix} = \begin{bmatrix} ~ x + t_x ~ \\ ~ y + t_y ~ \end{bmatrix} \]

2D point \(= (x, y, 1)^T\)

2D vector \(= (x, y, 0)^T\)

Matrix representation of translation

\[\begin{bmatrix} ~ x' ~ \\ ~ y' ~ \\ ~ w' ~ \end{bmatrix} = \begin{bmatrix} ~ 1 & 0 & t_x ~\\ ~ 0 & 1 & t_y ~ \\ ~ 0 & 0 & 1 ~ \end{bmatrix} \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ ~ 1 ~ \end{bmatrix} = \begin{bmatrix} ~ x + t_x ~ \\ ~ y + t_y ~ \\ ~ 1 ~ \end{bmatrix} \]

Valid operation if w-coordinate of result is \(1\) or \(0\)

  • vector + vector = vector
  • point - point = vector
  • point + vector = point
  • point + point = midpoint

In homogeneous coordinates, \(\begin{bmatrix} ~ x ~ \\ y \\ w \end{bmatrix}\) is the 2D point \(\begin{bmatrix} ~ x/w ~ \\ y/w \\ 1 \end{bmatrix},~w \neq 0\)

Affine map = linear map + translation (Linear Transforms First)

\[\begin{bmatrix} ~ x' ~ \\ ~ y' ~ \end{bmatrix} = \begin{bmatrix} ~ a & b ~ \\ ~ c & d ~ \end{bmatrix} \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ \end{bmatrix} + \begin{bmatrix} ~ t_x ~ \\ ~ t_y ~ \end{bmatrix} \]

Using homogeneous coordinates

\[\begin{bmatrix} ~ x' ~ \\ ~ y' ~ \\ ~ w' ~ \end{bmatrix} = \begin{bmatrix} ~ a & b & t_x ~\\ ~ c & d & t_y ~ \\ ~ 0 & 0 & 1 ~ \end{bmatrix} \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ ~ 1 ~ \end{bmatrix} \]

2D Transformations with homogeneous coordinates

Scale

\[\mathbf S(s_x, s_y) = \begin{bmatrix} ~ s_x & 0 & 0 ~\\ ~ 0 & s_y & 0 ~ \\ ~ 0 & 0 & 1 ~ \end{bmatrix} \]

Rotation

\[\mathbf R(\phi) = \begin{bmatrix} ~ \cos\phi & -\sin\phi & 0 ~ \\ ~ \sin\phi & \cos\phi & 0 ~ \\ ~ 0 & 0 & 1 ~ \end{bmatrix} \]

Translation

\[\mathbf T(t_x, t_y) = \begin{bmatrix} ~ 1 & 0 & t_x ~\\ ~ 0 & 1 & t_y ~ \\ ~ 0 & 0 & 1 ~ \end{bmatrix} \]

Inverse Transform

\[\mathbf x = \mathcal {M^{-1}} \mathbf x' \]

Composite Transform

Transform Ordering Matters !

Cause matrix multiplication is not commutative, matrices are applied right to left.

When we have a sequence of affine transforms \(A_1, A_2, A_3,~...\) :

Pre-multiply \(n\) matrices to obtain a single matrix for performance

\[A_n(...A_2(A_1(\mathbf x))) = \mathbf A_n \cdots \mathbf A_2 ~\cdot~ \mathbf A_1 ~\cdot~ \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ ~ 1 ~ \end{bmatrix} \]

Decomposing Complex Transform

eg. rotate around a given point c

\[\mathbf T(\mathbf c) \cdot \mathbf R(\mathbf \phi) \cdot \mathbf T(\mathbf {-c}) \]

3D transformations ? (#3)

Using homogeneous coordinates again !

  • 3D point = \((x, y, z, 1)^T\)
  • 3D vector = \((x, y, z, 0)^T\)

In general, \((x, y, z, w)~(w != 0)\) is the 3D point \((\cfrac{x}{w}, \cfrac{y}{w}, \cfrac{z}{w})\)

Use \(4 \times 4\) matrices for affine transformations

\[\begin{bmatrix} ~ x' ~ \\ ~ y' ~ \\ ~ z' ~ \\ ~ w' \end{bmatrix} = \begin{bmatrix} ~ a & b & c & t_x ~\\ ~ d & e & f & t_y ~ \\ ~ g & h & i & t_z ~ \\ ~ 0 & 0 & 0 & 1 ~ \end{bmatrix} \begin{bmatrix} ~ x ~ \\ ~ y ~ \\ ~ z ~ \\ ~ 1 ~ \end{bmatrix} \]

标签:begin,end,Vert,Review,2D,vec,bmatrix,mathbf,GAMES101
来源: https://www.cnblogs.com/siesta/p/GAMES101-1-2.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有