Lecture04 Transformation Cont.

Slide

3D transformations

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

  • Scale
    S ( s x , s y , s z ) = ( s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 ) S(s_x,s_y,s_z)=\begin{pmatrix}s_x&0&0&0\\0&s_y&0&0\\0&0&s_z&0\\0&0&0&1\end{pmatrix} S(sx,sy,sz)= sx0000sy0000sz00001

  • Translation
    T ( t x , t y , t z ) = ( 1 0 0 t x 0 1 0 t y 0 0 1 t z 0 0 0 1 ) T(t_x,t_y,t_z)=\begin{pmatrix}1&0&0&t_x\\0&1&0&t_y\\0&0&1&t_z\\0&0&0&1\end{pmatrix} T(tx,ty,tz)= 100001000010txtytz1

  • Rotation around x-, y-, or z-axis
    R x ( α ) = ( 1 0 0 0 0 cos ⁡ α − sin ⁡ α 0 0 sin ⁡ α cos ⁡ α 0 0 0 0 1 ) R_x(\alpha)=\begin{pmatrix}1&0&0&0\\0&\cos{\alpha}&-\sin{\alpha}&0\\0&\sin{\alpha}&\cos{\alpha}&0\\0&0&0&1\end{pmatrix} Rx(α)= 10000cosαsinα00sinαcosα00001
    R y ( α ) = ( cos ⁡ α 0 sin ⁡ α 0 0 1 0 0 − sin ⁡ α 0 cos ⁡ α 0 0 0 0 1 ) R_y(\alpha)=\begin{pmatrix}\cos{\alpha}&0&\sin{\alpha}&0\\0&1&0&0\\-\sin{\alpha}&0&\cos{\alpha}&0\\0&0&0&1\end{pmatrix} Ry(α)= cosα0sinα00100sinα0cosα00001
    R z ( α ) = ( cos ⁡ α − sin ⁡ α 0 0 sin ⁡ α cos ⁡ α 0 0 0 0 1 0 0 0 0 1 ) R_z(\alpha)=\begin{pmatrix}\cos{\alpha}&-\sin{\alpha}&0&0\\\sin{\alpha}&\cos{\alpha}&0&0\\0&0&1&0\\0&0&0&1\end{pmatrix} Rz(α)= cosαsinα00sinαcosα0000100001

  • 3D Rotations

    Compose any 3D rotation from R x , R y , R z R_x,R_y,R_z Rx,Ry,Rz?
    R x y z ( α , β , γ ) = R x ( α ) R y ( β ) R z ( γ ) R_{xyz}(\alpha,\beta,\gamma)=R_x(\alpha)R_y(\beta)R_z(\gamma) Rxyz(α,β,γ)=Rx(α)Ry(β)Rz(γ)

    • So-called Euler angles
    • Often used in flight simulators: roll, pitch, yaw

Rodrigues’ Rotaion Formula: Rotation by angle α \alpha α around axis n n n

R ( n , α ) = cos ⁡ α I + ( 1 − cos ⁡ α ) n n T + sin ⁡ α ( 0 − n z n y n z 0 − n x − n y n x 0 ) ⏟ N \bold{R}(\bold{n},\alpha)=\cos{\alpha}\bold{I}+(1-\cos{\alpha})\bold{n}\bold{n}^T+\sin{\alpha}\underbrace{\begin{pmatrix}0&-n_z&n_y\\ n_z&0&-n_x\\ -n_y&n_x&0\end{pmatrix}}_\text{N} R(n,α)=cosαI+(1cosα)nnT+sinαN 0nznynz0nxnynx0

Viewing transformation

View / Camera transformation

  • What is view transformation?
  • Think about how to take a photo
    • Find a good place and arrange people (model transformation)
    • Find a good ‘angle’ to put the camera (view transformation)
    • Cheese! (projection transformation)
  • How to perform view transformation?
  • Define the camera first
    • Position e ⃗ \vec{e} e
    • Look-at / gaze direction g ^ \hat{g} g^
    • Up direction t ^ \hat{t} t^
  • Key observation
    • If the camera and all objects move together, the ‘photo’ will be the same
  • How about that we always transform the camera to
    • The origin, up at Y, look at -Z
    • And transform the objects along with the camera
  • Transform the camera by M v i e w M_{view} Mview
    • So it’s located at the origin, up at Y, look at -Z
  • M v i e w M_{view} Mview in math?
    • Let’s write M v i e w = R v i e w T v i e w M_{view}=R_{view}T_{view} Mview=RviewTview
    • Translate e to origin
      T v i e w = [ 1 0 0 − x e 0 1 0 − y e 0 0 1 − z e 0 0 0 1 ] T_{view}=\begin{bmatrix}1&0&0&-x_e\\0&1&0&-y_e\\0&0&1&-z_e\\0&0&0&1\end{bmatrix} Tview= 100001000010xeyeze1
    • Rotate g to -Z, t to Y, (g x t) to X
    • Consder its inverse rotation: X to (g x t), Y to t, Z to -g
      R v i e w − 1 = [ x g ^ × t ^ x t x − g 0 y g ^ × t ^ y t y − g 0 z g ^ × t ^ z t z − g 0 0 0 0 1 ] ⇒ R v i e w = [ x g ^ × t ^ y g ^ × t ^ z g ^ × t ^ 0 x t y t z t 0 x − g y − g z − g 0 0 0 0 1 ] R_{view}^{-1}= \begin{bmatrix} x_{\hat{g}\times\hat{t}}&x_t&x_{-g}&0\\ y_{\hat{g}\times\hat{t}}&y_t&y_{-g}&0\\ z_{\hat{g}\times\hat{t}}&z_t&z_{-g}&0\\ 0&0&0&1 \end{bmatrix} \Rightarrow R_{view}= \begin{bmatrix} x_{\hat{g}\times\hat{t}}&y_{\hat{g}\times\hat{t}}&z_{\hat{g}\times\hat{t}}&0\\ x_t&y_t&z_t&0\\ x_{-g}&y_{-g}&z_{-g}&0\\ 0&0&0&1 \end{bmatrix} Rview1= xg^×t^yg^×t^zg^×t^0xtytzt0xgygzg00001 Rview= xg^×t^xtxg0yg^×t^ytyg0zg^×t^ztzg00001
  • Summary
    • Transform objects together with the camera
    • Until camera’s at the origin, up at Y, look at -Z
  • Also known as ModelView Transformation

Projection transformation

  • Projection in Computer Graphics
    • 3D to 2D
    • Orthographic projection
    • Perspective projection
Orthographic projection
  • A simple way of understanding
    • Camera located at origin, looking at -Z, up at Y
    • Drop Z coordinate
    • Translate and scale the result rectangle to [ − 1 , 1 ] 2 [-1,1]^{2} [1,1]2
  • In general
    • We want to map a cubiod [ l , r ] × [ b , t ] × [ f , n ] [l,r]\times[b,t]\times[\bold{f},\bold{n}] [l,r]×[b,t]×[f,n] to the ‘canonical’ cube [ − 1 , 1 ] 3 [-1,1]^{3} [1,1]3
  • Slightly different orders
    • Center cuboid by translating
    • Scale into ‘canonical’ cube
  • Transformation matrix?
    • Translate (center to origin) first, then scale (length / width / height to 2)
      M o r t h o = [ 2 r − l 0 0 0 0 2 t − b 0 0 0 0 2 n − f 0 0 0 0 1 ] [ 1 0 0 − r + l 2 0 1 0 − t + b 2 0 0 1 − n + f 2 0 0 0 1 ] M_{ortho}= \begin{bmatrix} \frac{2}{r-l}&0&0&0\\ 0&\frac{2}{t-b}&0&0\\ 0&0&\frac{2}{n-f}&0\\ 0&0&0&1 \end{bmatrix} \begin{bmatrix} 1&0&0&-\frac{r+l}{2}\\ 0&1&0&-\frac{t+b}{2}\\ 0&0&1&-\frac{n+f}{2}\\ 0&0&0&1 \end{bmatrix} Mortho= rl20000tb20000nf200001 1000010000102r+l2t+b2n+f1
  • Caveat
    • Looking at / along -Z is making near and far not intuitive (n > f)
    • FYI: that’s why OpenGL (a Graphic 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 n\rightarrow n nn, f → f f\rightarrow f ff) ( M p e r s p → o r t h o M_{persp\rightarrow ortho} Mpersportho)
    • Do orthographic projection ( M o r t h o M_{ortho} Mortho, already known!)
  • In order to find a transformation
    • Recall the key idea: Find the relationship between transformed points ( x ′ , y ′ , z ′ ) (x',y',z') (x,y,z) and the original points ( x , y , z ) (x,y,z) (x,y,z)
      y ′ = n z y x ′ = n z x (similar to y’) y'=\frac{n}{z}y\qquad x'=\frac{n}{z}x\quad\text{(similar to y')} y=znyx=znx(similar to y’)
  • In homongeneous coordinates,
    ( x y z 1 ) ⇒ ( n x / z n y / z unknown 1 ) = ( n x n y still unknown z ) \begin{pmatrix}x\\y\\z\\1\end{pmatrix}\Rightarrow \begin{pmatrix}nx/z\\ny/z\\\text{unknown}\\1\end{pmatrix}= \begin{pmatrix}nx\\ny\\\text{still unknown}\\z\end{pmatrix} xyz1 nx/zny/zunknown1 = nxnystill unknownz
  • So the ‘squish’ (persp to ortho) projection does this
    M p e r s p → o r t h o 4 × 4 ( x y z ) = ( n x n y unknown z ) M^{4\times4}_{persp\rightarrow ortho}\begin{pmatrix}x\\y\\z\end{pmatrix}=\begin{pmatrix}nx\\ny\\\text{unknown}\\z\end{pmatrix} Mpersportho4×4 xyz = nxnyunknownz
  • Already good enough to figure out a part of M p e r s p → o r t h o M_{persp\rightarrow ortho} Mpersportho
    M p e r s p → o r t h o = ( n 0 0 0 0 n 0 n ? ? ? ? 0 0 1 0 ) M_{persp\rightarrow ortho}= \begin{pmatrix}n&0&0&0\\0&n&0&n\\?&?&?&?\\0&0&1&0\end{pmatrix} Mpersportho= n0?00n?000?10n?0
  • How to figure out the third row of M p e r s p → o r t h o M_{persp\rightarrow ortho} Mpersportho
    • Any information that we can use?
  • Observation: the third row is responsible for z’
    • Any point on the near plane will not change
      • So the third row must be of the form ( 0 , 0 , A , B ) (0,0,A,B) (0,0,A,B)
    • Any point’s z on the far plane will not change
      • A n + b = n 2 An+b=n^2 An+b=n2
      • A f + B = f 2 Af+B=f^2 Af+B=f2
  • Finally, every entry in M p e r s p → o r t h o M_{persp\rightarrow ortho} Mpersportho is known!
  • What’s next?
    • Do orthographic projection ( M o r t h o M_{ortho} Mortho) to finish
    • M p e r s p = M o r t h o M p e r s p → o r t h o M_{persp}=M_{ortho}M_{persp\rightarrow ortho} Mpersp=MorthoMpersportho
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值