Lecture 01 Overview of Computer Graphics
现代计算机图形学的应用
Lecture 02 Review of Linear Algebra
一、Vector Multiplication
(一)、Dot(scalar) Product
1、The Basic Definition of The Dot Product
![image-20210111111503612](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111111503612.png)
![image-20210111111615539](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111111615539.png)
- The basic definition of the dot product(最标准的定义式)
![image-20210111111953565](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111111953565.png)
-
Find angle between two vectors(求两个向量的夹角)
e.g. cosine of angle between light source and surface(例如光源与表面夹角余弦)
![image-20210111112133879](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111112133879.png)
- For unit vectors (当 a和b为单位向量时,上述的式子可以写成此式)
2、Dot Product in Cartesian Coordinates
- Component-wise multiplication, then adding up
– in 2D
![image-20210111113028977](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111113028977.png)
–in 3D
![image-20210111113235185](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111113235185.png)
3、Dot Product in Graphics
(1)Decompose a Vector
![image-20210111115014294](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111115014294.png)
求b在a上的投影可以用下面的式子:
求出来投影以后,就可以任意将b分解为垂直与平行的两个向量
一个方向即为b,另一个方向为b-b⊥
(2)Determine Forward / Backward
![image-20210111120827565](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111120827565.png)
两个向量点乘结果>0,则两个向量同向
两个向量点乘结果<0,则两个向量反向
(3)Measure How Close Two Directions
如上图,若两个向量越近,则点乘结果越接近于1,直到两个向量完全平行,此时点乘结果为1;
若两个向量越远,则点乘结果越接近于0,直到两个向量完全相反,此时点乘结果为-1;
当两个向量垂直时,点乘结果为0
(二)、Cross (vector) Product
1、The Basic Definition of The Cross Product
![image-20210111121432517](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111121432517.png)
- Cross product is orthogonal to two initial vectors (外积正交于两个初始向量)
- Direction determined by right-hand rule (通过右手定则判断叉乘结果向量的方向)
- Useful in constructing coordinate systems (在构建空间坐标系的时候很有用)
2、Cross product: Properties
![image-20210111133507278](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111133507278.png)
3、Cross Product in Graphics
(1)Determine left / right
![image-20210111133724520](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111133724520.png)
判断向量a和向量b的位置关系
用向量a叉乘向量b,即a×b,若得到的结果为正(说明叉乘的结果向量(z)向外,如果用右手螺旋定则去判断,说明大拇指指向外,而根据叉乘顺序是a叉乘b,说明四指由a转向b),则b在a的左侧;若得到的结果为负(说明叉乘的结果向量(z)向内,如果用右手螺旋定则去判断,说明大拇指指向内,而根据叉乘顺序是a叉乘b,说明四指由a转向b),则a在b的左侧;
同理,还可以
用向量b叉乘向量a,即b×a,若得到的结果为正,则b在a的右侧,若得到的结果为负,则a在b的右侧
(2)Determine inside / outside
![image-20210111135201091](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111135201091.png)
判断点P在三角形ABC内部
默认组成三角形的三个点是逆时针方向排列
首先用向量AB与向量AP叉乘,若结果为正,说明向量AP(点p)在向量AB的左侧
然后用向量BC与向量BP叉乘,若结果为正,说明向量BP(点p)在向量BC的左侧
最后用向量CA与向量CP叉乘,若结果为正,说明向量CP(点p)在向量CA的左侧
若以上三个式子都成立,则说明点p在AB、BC、CA的左侧,则点p在三角形ABC内
(三)、Orthonormal Bases / Coordinate Frames
Orthonormal Coordinate Frames
-
Important for representing points, positions, locations
-
Often, many sets of coordinate systems
--Global, local, world, model, parts of model (head,hands, …)
-
Critical issue is transforming between these systems/bases
Any set of 3 vectors (in 3D) that
![image-20210111140702372](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111140702372.png)
用向量叉乘可以定义一些相互垂直的轴,这些轴就会形成一个坐标系。
上式中定义了u、v、w三个单位向量,且相互点乘都为0(即互相垂直),w即可通过u×v得到(右手系)
![image-20210111141114700](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111141114700.png)
这样定义的好处是可以把任意一个向量分解到三个轴上(如上式)
二、Matrices
(一)、Matrix-Matrix Multiplication
1、The Basic Operation of Matrix Multiplication
(number of) columns in A must = # rows in B
(M x N) (N x P) = (M x P)
两个矩阵可以做乘法的前提是第一个矩阵的列与第二个矩阵的行相等,得到的新矩阵行数是第一个矩阵的行,列是第二个矩阵的列。
矩阵乘法的计算方法:
![image-20210111141752636](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111141752636.png)
若要算第一行第二列位置的值,则用第一个矩阵的第一行与第二个矩阵的第二列求点乘(对应元素相乘后相加),即可得到
Element (i, j) in the product is the dot product of row i from A and column j from B
2、Properties
(1)、Non-commutative
AB and BA are different in general
(2)、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×1) (始终认为矩阵在左边,向量在右边,向量永远是一个列向量(m×1的矩阵))
-
Key for transforming points
-
Official spoiler: 2D reflection about y-axis
沿y轴作对称操作
(三)、Transpose of a Matrix
- Switch rows and columns (ij -> ji)
![image-20210111143208016](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143208016.png)
矩阵转置:行列互换
- Property
![image-20210111143235767](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143235767.png)
(四)、Identity Matrix and Inverses
- 单位矩阵
![image-20210111143338865](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143338865.png)
- 逆矩阵
![image-20210111143407839](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143407839.png)
(五)、Vector multiplication in Matrix form
![image-20210111143654010](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143654010.png)
![image-20210111143739705](https://gitee.com/dmtzhuozhuo/computer-graphics/raw/master/img/image-20210111143739705.png)