Linear Algebra
和所有课一样,lecture2 做了线性代数的复习课
这里只摘录了一些补充
Cross product
叉乘具有向量表示
左边 3x3 的矩阵叫做 dual matrix of vector
Homogenous Coordinates and Transformation
Homogenous Coordinates: 齐次坐标
Affine map = linear map + translation
通过增加一个维度的方法,可以统一仿射变换为矩阵乘法形式。
- Translation cannot be represented in matrix form
- But we don’t want translation to be a special case
- Is there a unified way to represent all transformations?(and what’s the cost?)
用齐次坐标,能够统一所有的图形变换
More Definition
Add a third coordinate(w-coordinate)
- 2D point
- 2D vector
dim-3 补0的向量就不会被受平移影响
Matrix representation of translations
增加第三维度,1为点,0为向量.
做以上矩阵乘法运算,向量vector不会受影响,但是 Point 会出现平移
Valid operation if w-coordinate of result is 1 or 0
- vec + vec = vec
- point - point = vec
- point + vec = point
- point + point = ??
扩充定义
当
不为1时,默认可以对向量所有元素除去
引入齐次坐标,可以直接将平移变换融入矩阵乘法。
inverse transform
composing transforms
Sequence of affine transforms
- Compose by matrix multiplication
- Very important for performance!
多个n维矩阵乘积得到的单个矩阵,反映复合变换
rotate around any point
无特别指明,永远围绕原点旋转
Transform Ordering Matters!
- Translate center to origin.
- Rotate.
- Translate back.
Matrix representation?
3D transformations
Use 4 by 4 matrices for affine transformations
先应用了线性变换再加上了平移量。
- 旋转的变换就是前3维度,基变换
- Rotation around x-, y-, or z-axis
- Rotation around x-, y-, or z-axis
Compose any 3D rotation from
- So-called Euler angles
- Often used in flight simulators: roll, pitch, yaw
Rodrigues’s Rotation Formula
Rotation by angle
参考资料:
https://blog.csdn.net/weixin_40215443/article/details/123950141
https://sites.cs.ucsb.edu/~lingqi/teaching/resources/GAMES101_Lecture_04_supp.pdf
闫老师这个真的看不懂。。。
缩放scale是单位矩阵的对应维度的数乘
- Scale
- Scale
位移是最后一列的加减
- Translation
- Translation
Viewing transformation
aka Camera Transformation
- Viewing transformation
- View/Camera transformation
- Projection transformation
- Orthographic projection
- Perspective projection
- model transformation
- view tranformation
- projection transformation
Define the camera
- Position
- Look-at /gaze direction
- Up direction
Key observation
If the camera and all objects move together, the “photo” will be the same
SO we always transform the camera to
- The origin, up at Y, look at -Z
- transform the objects along with the camera
对于任意位置的相机和物体,变换到原点处基本思路:
- 平移到原点
- 旋转g->-Z
- 旋转t->Y
- (g x t)自然与X轴对齐
这里旋转矩阵求逆,利用了正交矩阵的性质,旋转等于取逆
Also known as ModelView Transformation
for projection transformation
Projection
- Projection in Computer Graphics
- 3D to 2D
- Orthographic projection
- Perspective projection
Orthographic Projection
- A simple way of undersatanding
- Cam located at origin, looking at -Z, up at Y
- Drop Z coordinate
- Translate and scale the resulting rectangle to
相机固定于原点,看向-Z方向,可以忽略-Z维度
在空间里定义一个立方体
然后将立方体 [l, r] x [b, t] x [f, n] to the “canonical” cube
- Transformation matrix
- transalte(center to origin) first, then scale(length/width/height to 2)
- Caveat
- Looking at/along -Z is making near and far not intuitive(n>f)
- FYI:that’s why OpenGL(a Graphics API) uses left hand coords
Perspective Projection
- Most common in Computer Graphics, art, visual system.
- Further objects are smaller.
- Parallel lines not parallel; converge to single point.
- How to do perspective projection
- First “squish” the frustum into a cuboid(n->n, f->f)(
) - Do orthographic projection(
, already known!)
- First “squish” the frustum into a cuboid(n->n, f->f)(
先做挤压操作,把frustum挤压成长方体
远平面挤压,近平面不变被认为是,将远平面挤压变形同近平面,再做正交投影
- In order to find a transformation
- Find the relationship between transformed points(x’, y’, z’) and the original points(x, y, z)
根据远近平面的设定 In homogeneous coordinates
- Any point on the near plane will not change
- Any point’s z on the far plane will not change
根据近平面和远平面的两个设定(利用了近平面不变,远平面中心不变)作为边值条件,求得变换矩阵
对于任意距离的平面,经过以上的形变,距离会被压缩的更远
可以参考 知乎文章
注意:n和f的设定一定是等符号的,这由透视投影的物理场景决定。
- Finally, every entry in
- Post title: GAMES101_1
- Create time: 2022-07-27 16:12:07
- Post link: computer-graphics/games101-1/
- Copyright notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.