# 3D geometric transformation ###### tags: `course` `computer graphic` Building up a scene using 3-D transformation to instance objects Projecting 3D objects onto a 2D view plane # translation (位移,移動一個物體位置) # Rotation (旋轉) 四種旋轉參考點 1. 原點 2. 定點 3. 軸 4. 隨便一條直線 # Scaling(形變,不一定是所有向量一起,可以單邊變形) ex: 拉長,變寬 # shearing(剪力) ex:對X軸做shear ``` x' = x + y cot(theta) y' = y z' = z ``` # Affine transformation(仿射變換) 是指在幾何中,一個向量空間進行一次線性變換並接上一個平移,變換為另一個向量空間。 EX: X' = LX + b Affine Transformation可以保證轉換完後的點間比例相同,也可以保持平行 # Homogeneous Coordinates 從卡式空間(Cartesian space)轉到homogeneous space(把常數向當成一個新的維度) ``` Mapping (x, y, z)  (X, Y, Z, W) by x = X/W, y = Y/W, z = Z/W, W  0 ``` ## affine transformation in Homogenous Coordinates ![](https://i.imgur.com/xIxnWei.png) > 有12個自由度 > 為了保持w等於1,所以最底下row是[0,0,0,1] ## Translation: p' = T p in Homogenous Coordinates ![](https://i.imgur.com/v7PE8wX.png) > 原本座標加上位移 [ax,ay,az] ## Scaling: p' =T p in Homegenous Coordinates ![](https://i.imgur.com/2ZvvUac.png) > 原本座標對原點進行縮放 [Bx,By,Bz] ## Rotation: p' =Rz p in Homegenous Coordinates ![](https://i.imgur.com/pe0dlgW.png) > 以z軸為基準旋轉 ## Shearing: p' =Hz p in Homegenous Coordinates ![](https://i.imgur.com/UFSzHeo.png) ## Concatenation of transformations q =CBAp = C(B(Ap))=Mp, where M=CBA > 就是先把所有轉移矩陣乘成一個 ### Rotation about a fixed point ex:延與Z軸方向平行之軸旋轉 M=T(p)Rz(theta)T(-p) > 想法:把物體軸位移至Z軸,轉完在回覆原始位置 ### Rotation about the origin R=Rx Ry Rz > 想法:先轉一個軸 ### Rotation about an arbitrary point and line ![](https://i.imgur.com/7xGSJbm.png) > 把參考點移到原點 > 轉完在回覆