GAMES101笔记_Lec03~04_变换 Transform

1 为什么学习变换 Why study transformation

1.1 模型变换 Modeling

  • 场景展示——描述摄像机的位置移动
  • 机器人跳舞——物体的旋转
  • 皮克斯开场动画台灯压扁字母I——物体的缩放

1.2 视图变换 Viewing

  • 光栅化成像中涉及大量的视图变换
    在这里插入图片描述

2 二维变换 2D Transformations

3B1B线代的本质(可视化理解线性变换):https://www.bilibili.com/video/BV1ns41167b9?spm_id_from=333.999.0.0

2.1 缩放变换矩阵 Scale Matrix

  • 不锁定比例的 Non-Uniform
    在这里插入图片描述

( x ′ y ′ ) = ( s x 0 0 s y ) ( x y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { s _ { x } } & { 0 } \\ { 0 } & { s _ { y } } \end{pmatrix} \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} (xy)=(sx00sy)(xy)

2.2 对称变换矩阵 Reflection Matrix

  • 水平翻转 Horizontal reflection:
    在这里插入图片描述

( x ′ y ′ ) = ( − 1 0 0 1 ) ( x y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { - 1 } & { 0 } \\ { 0 } & { 1 } \end{pmatrix} \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} (xy)=(1001)(xy)

2.3 切变变换矩阵 Shear Matrix

  • 水平方向位移在y=0处是0,在y=1处是a,竖直方向位移总是0
    在这里插入图片描述

( x ′ y ′ ) = ( 1 a 0 1 ) ( x y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { 1 } & { a } \\ { 0 } & { 1 } \end{pmatrix} \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} (xy)=(10a1)(xy)

2.4 旋转变换矩阵(默认绕原点、逆时针方向) Rotation Matrix

  • 旋转的角度为θ
    在这里插入图片描述

R θ = ( cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ) R _ { \theta } = \begin{pmatrix} { } { \cos \theta } & { -\sin \theta } \\ { \sin \theta } & { \cos \theta } \end{pmatrix} Rθ=(cosθsinθsinθcosθ)

2.5 线性变换 Linear Transforms

  • 使用相同维度的矩阵相乘,形式为坐标与矩阵相乘得到新的坐标
    ( x ′ y ′ ) = ( a b c d ) ( x y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { a } & { b } \\ { c } & { d } \end{pmatrix} \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} (xy)=(acbd)(xy)

3 齐次坐标 Homogeneous Coordinates

3.1 为什么学习齐次坐标 Why homogeneous coordinates

  • 平移变换不是线性变换,无法直接用矩阵形式表示
    在这里插入图片描述

( x ′ y ′ ) = ( a b c d ) ( x y ) + ( t x t y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { a } & { b } \\ { c } & { d } \end{pmatrix} \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} + \begin{pmatrix} { } { t _ { x } } \\ { t y } \end{pmatrix} (xy)=(acbd)(xy)+(txty)

  • 我们不想把平移当作一个特殊的变换 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?)

3.2 通过齐次坐标解决问题 Solution: Homogenous Coordinates

3.2.1 添加第三个坐标 Add a third coordinate (w-coordinate)

2 D   p o i n t = ( x , y , 1 ) T , 2 D   v e c t o r = ( x , y , 0 ) T \rm{2D\,point}=(x,y,1)^T,\quad\rm{2D\,vector}=(x,y,0)^T 2Dpoint=(x,y,1)T,2Dvector=(x,y,0)T

3.2.2 平移的矩阵表示 Matrix representation of translations

( x ′ y ′ w ′ ) = ( 1 0 t x 0 1 t y 0 0 1 ) ⋅ ( x y 1 ) = ( x + t x y + t y 1 ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \\ { w ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { 1 } & { 0 } & { t_x } \\ { 0 } & { 1 } & { t_y } \\ { 0 } & { 0 } & { 1 } \end{pmatrix}\cdot\begin{pmatrix} { } { x } \\ { y } \\ { 1 } \end{pmatrix} = \begin{pmatrix} { } { x + t_x } \\ { y + t_y } \\ { 1 } \end{pmatrix} xyw=100010txty1xy1=x+txy+ty1

3.2.3 如果平移的是一个向量? What if you translate a vector?

  • 向量具有平移不变性,经过平移变换后还是原向量
    ( x ′ y ′ w ′ ) = ( 1 0 t x 0 1 t y 0 0 1 ) ⋅ ( x y 0 ) = ( x y 0 ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \\ { w ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { 1 } & { 0 } & { t_x } \\ { 0 } & { 1 } & { t_y } \\ { 0 } & { 0 } & { 1 } \end{pmatrix}\cdot\begin{pmatrix} { } { x } \\ { y } \\ { 0 } \end{pmatrix} = \begin{pmatrix} { } { x } \\ { y } \\ { 0 } \end{pmatrix} xyw=100010txty1xy0=xy0

3.2.4 齐次坐标的妙处

  • 如果w-coordinate的结果是1或0则为有效操作,这样既能让平移变换形式统一,也保留了向量和点加减运算的可操作性
  • 使用齐次坐标时,(x, y, w)表示平面内一点(x/w, y/w, 1), w≠0
    • vector + vector = vector 0+0=0
    • point – point = vector 1-1=0
    • point + vector = point 1+0=1
    • point + point = ??

point+point得到的结果为两个点连线的中点(将w-coordinate化为1)

3.2.5 仿射变换 Affine Transformations

  • 仿射变换 = 线性变换 + 平移变换 Affine map = linear map + translation
    ( x ′ y ′ ) = ( a b c d ) ⋅ ( x y ) + ( t x t y ) \begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \end{pmatrix} = \begin{pmatrix} { } { a } & { b } \\ { c } & { d } \end{pmatrix} \cdot \begin{pmatrix} { } { x } \\ { y } \end{pmatrix} + \begin{pmatrix} { } { t_x } \\ { t_y } \end{pmatrix} (xy)=(acbd)(xy)+(txty)
  • 使用齐次坐标 Using homogenous coordinates:
    A f f i n e    T r a n s f o r m a t i o n s : ( x ′ y ′ 1 ) = ( a b t x c d t y 0 0 1 ) ⋅ ( x y 1 ) \rm{Affine\;Transformations:}\begin{pmatrix} { } { x ^ { \prime } } \\ { y ^ { \prime } } \\ { 1 } \end{pmatrix} = \begin{pmatrix} { } { a } & { b } & { t _ { x } } \\ { c } & { d } & { t _ { y } } \\ { 0 } & { 0 } & { 1 } \end{pmatrix} \cdot \begin{pmatrix} { } { x } \\ { y }\\{1} \end{pmatrix} AffineTransformationsxy1=ac0bd0txty1xy1

3.2.6 使用齐次坐标的2D变换 2D Transformations

S c a l e : S ( s x , s y ) = ( s x 0 0 0 s y 0 0 0 1 ) \rm{Scale:}S (s _ { x , } s _ { y } ) = \begin{pmatrix} {} { s _ { x } } & { 0 } & { 0 } \\ { 0 } & { s _ { y } } & { 0 } \\ { 0 } & { 0 } & { 1 } \end{pmatrix} ScaleS(sx,sy)=s

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值