Lecture03 Transform

Slide

Why study transformation

Modeling

  • translation
  • rotation
  • scaling

Viewing

  • (3D to 2D) projection

2D transformations

  • Scale
    [ x ′ y ′ ] = [ s x 0 0 s y ] [ x y ] \begin{bmatrix}x'\\y'\end{bmatrix}=\begin{bmatrix}s_x&0\\0&s_y\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} [xy]=[sx00sy][xy]
    • Reflection Matrix
      [ x ′ y ′ ] = [ − 1 0 0 1 ] [ x y ] \begin{bmatrix}x'\\y'\end{bmatrix}=\begin{bmatrix}-1&0\\0&1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} [xy]=[1001][xy]
    • Shear Matrix
      [ x ′ y ′ ] = [ 1 a 0 1 ] [ x y ] \begin{bmatrix}x'\\y'\end{bmatrix}=\begin{bmatrix}1&a\\0&1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} [xy]=[10a1][xy]
  • Rotate
    R θ = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] R_\theta=\begin{bmatrix}\cos{\theta}&-\sin{\theta}\\\sin{\theta}&\cos{\theta}\end{bmatrix} Rθ=[cosθsinθsinθcosθ]
  • Linear Transforms = Matrices
    [ x ′ y ′ ] = [ a b c d ] [ x y ] \begin{bmatrix}x'\\y'\end{bmatrix}=\begin{bmatrix}a&b\\c&d\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} [xy]=[acbd][xy]
    x ′ = M x x'=\bold{M}x x=Mx

Homogeneous coordinates

Why Homogeneous Coordinates

  • Translation cannot be represented in matrix form
    [ x ′ y ′ ] = [ a b c d ] [ x y ] + [ t x t y ] \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} [xy]=[acbd][xy]+[txty]
    (So, translation is NOT linear transform!)
  • 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?)

Solution: Homogenous Coordinates

Add a third coordinate (w-coordinate)

  • 2D point = ( x , y , 1 ) T (x,y,1)^T (x,y,1)T
  • 2D vector = ( x , y , 0 ) T (x,y,0)^T (x,y,0)T

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'\\y'\\w'\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 = 100010txty1 xy1 = x+txy+ty1

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

  • vector + vector = vector
  • point - point = vector
  • point + vector = point
  • point + point = ??

In homogeneous coordinates, ( x y w ) \begin{pmatrix}x\\y\\w\end{pmatrix} xyw is the 2D point ( x / w y / w 1 ) \begin{pmatrix}x/w\\y/w\\1\end{pmatrix} x/wy/w1 , w ≠ 0 w\neq0 w=0

Affine Transformations

Affine map = linear map + translation

( x ′ y ′ ) = ( a b c d ) ⋅ ( x y ) + ( t x t y ) \begin{pmatrix}x'\\y'\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:

( x ′ y ′ 1 ) = ( a b t x c d t y 0 0 1 ) ⋅ ( x y 1 ) = ( x y 1 ) \begin{pmatrix}x'\\y'\\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}=\begin{pmatrix}x\\y\\1\end{pmatrix} xy1 = ac0bd0txty1 xy1 = xy1

2D Transformations

  • Scale
    S ( s x , s y ) = ( s x 0 0 0 s y 0 0 0 1 ) S(s_x,s_y)=\begin{pmatrix}s_x&0&0\\0&s_y&0\\0&0&1\end{pmatrix} S(sx,sy)= sx000sy0001
  • Rotation
    R ( α ) = ( cos ⁡ α − sin ⁡ α 0 sin ⁡ α cos ⁡ α 0 0 0 1 ) R(\alpha)=\begin{pmatrix}\cos{\alpha}&-\sin{\alpha}&0\\\sin{\alpha}&\cos{\alpha}&0\\0&0&1\end{pmatrix} R(α)= cosαsinα0sinαcosα0001
  • Translation
    T ( t x , t y ) = ( 1 0 t x 0 1 t y 0 0 1 ) T(t_x,t_y)=\begin{pmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{pmatrix} T(tx,ty)= 100010txty1

Inverse Transform

M − 1 M^{-1} M1 is the inverse of transform M M M in both a matrix and geometric sense

Composite Transform

Transform Odering Matters!

Matrix multiplication is not commutative

R 45 ⋅ T ( 1 , 0 ) ≠ T ( 1 , 0 ) ⋅ R 45 R_{45}\cdot T_{(1,0)}\neq T_{(1,0)}\cdot R_{45} R45T(1,0)=T(1,0)R45

Note that matrices are applied right to left:

T ( 1 , 0 ) ⋅ R 45 [ x y 1 ] = [ 1 0 1 0 1 0 0 0 1 ] [ cos ⁡ 4 5 ∘ − sin ⁡ 4 5 ∘ 0 sin ⁡ 4 5 ∘ cos ⁡ 4 5 ∘ 0 0 0 1 ] [ x y 1 ] T_{(1,0)}\cdot R_{45}\begin{bmatrix}x\\y\\1\end{bmatrix}= \begin{bmatrix} 1&0&1\\ 0&1&0\\ 0&0&1 \end{bmatrix} \begin{bmatrix} \cos{45^\circ}&-\sin{45^\circ}&0\\ \sin{45^\circ}&\cos{45^\circ}&0\\ 0&0&1 \end{bmatrix} \begin{bmatrix} x\\y\\1 \end{bmatrix} T(1,0)R45 xy1 = 100010101 cos45sin450sin45cos450001 xy1

Sequence of affine transforms A 1 A_1 A1, A 2 A_2 A2, A 3 A_3 A3, …

  • Compose by matrix multiplication
    • Very important for performance!
      A n ( … A 2 ( A 1 ( x ) ) ) = A n ⋯ A 2 ⋅ A 1 ⋅ ( x y 1 ) A_n(\dots A_2(A_1(x)))=A_n\cdots A_2\cdot A_1\cdot\begin{pmatrix}x\\y\\1\end{pmatrix} An(A2(A1(x)))=AnA2A1 xy1

Decomposing Complex Transforms

How to rotate around a given point c?

  1. Translate center to origin
  2. Rotate
  3. Translate back

3D Transforms

Use homogeneous coordinates again:

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

In general, ( x , y , z , w ) ( w ≠ 0 ) (x,y,z,w)(w\neq0) (x,y,z,w)(w=0) is the 3D point: ( x / w , y / w , z / w ) (x/w,y/w,z/w) (x/w,y/w,z/w)

Use 4 × 4 4\times4 4×4 matrices for affine transformations

( x ′ y ′ z ′ 1 ) = ( a b c t x d e f t u g h i t z 0 0 0 1 ) ⋅ ( x y z 1 ) \begin{pmatrix} x'\\y'\\z'\\1 \end{pmatrix}= \begin{pmatrix} a&b&c&t_x\\d&e&f&t_u\\g&h&i&t_z\\0&0&0&1 \end{pmatrix} \cdot \begin{pmatrix} x\\y\\z\\1 \end{pmatrix} xyz1 = adg0beh0cfi0txtutz1 xyz1

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值