Posted on

Table of Contents

Transformation matrices can describe the Linear Transforms like scaling, shearing, rotation, and projection of an object. P=MP \mathbf{P'} = \mathbf{M}\mathbf{P}

Scale Transform

P=SP=[Sx0000Sy0000Sz00001][XYZ1]=[SxXSyYSzZ1] \mathbf{P'} = \mathbf{S}\mathbf{P} = \begin{bmatrix} S_x & 0 & 0 & 0 \cr 0 & S_y & 0 & 0 \cr 0 & 0 & S_z & 0 \cr 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \cr Y \cr Z \cr 1 \end{bmatrix}= \begin{bmatrix} S_xX \cr S_yY \cr S_zZ \cr 1 \end{bmatrix}

This also works with Reflection when Si<0S_i < 0

Shear Matrix

P=SrP=[1SrxySrxz0Sryx1Sryz0SrzxSrzy100001][XYZ1]=[X+SrxyY+SrxzZY+SryxX+SryzZZ+SrzxX+SrzyY1] \mathbf{P'} = \mathbf{Sr}\mathbf{P} = \begin{bmatrix} 1 & Sr_{xy} & Sr_{xz} & 0 \cr Sr_{yx} & 1 & Sr_{yz} & 0 \cr Sr_{zx} & Sr_{zy} & 1 & 0 \cr 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \cr Y \cr Z \cr 1 \end{bmatrix}= \begin{bmatrix} X + Sr_{xy}Y + Sr_{xz}Z \cr Y + Sr_{yx}X + Sr_{yz}Z \cr Z + Sr_{zx}X + Sr_{zy}Y \cr 1 \end{bmatrix}

Rotation Matrix

First, consider a 2D case, rotate around Origin [0,0][0,0] and anti-clockwise θ\theta. R(θ)=[cosθsinθsinθcosθ] \mathbf{R}(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \cr \sin\theta & \cos\theta \end{bmatrix} Then in 3D, we can consider as 3 similar rotation around X,Y,Z-axis by angle θ\theta

  • Rotation around the X-axis by an angle θ\theta

Rx(θ)=[10000cosθsinθ00sinθcosθ00001] \mathbf{R}_{x}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \cr 0 & \cos\theta & -\sin\theta & 0 \cr 0 & \sin\theta & \cos\theta & 0 \cr 0 & 0 & 0 & 1 \end{bmatrix}

  • Rotation around the Y-axis by an angle θ\theta

Ry(θ)=[cosθ0sinθ00100sinθ0cosθ00001] \mathbf{R}_{y}(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta & 0 \cr 0 & 1 & 0 & 0 \cr -\sin\theta & 0 & \cos\theta & 0 \cr 0 & 0 & 0 & 1 \end{bmatrix}

Note: here the sinθ-\sin\theta is in RzxR_{zx} and and sinθ\sin\theta in RxzR_{xz}. That's because in our coordinates, Y=Z×X\mathbf{Y}=\mathbf{Z}\times\mathbf{X}.

  • Rotation around the Z-axis by an angle θ\theta

Rz(θ)=[cosθsinθ00sinθcosθ0000100001] \mathbf{R}_{z}(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 & 0 \cr \sin\theta & \cos\theta & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & 1 \end{bmatrix}

Rotation in 3D can be composed by 3 Rotations around each axis. Rxyz(α,β,γ)=Rx(α)Ry(β)Rz(γ) \mathbf{R}_{xyz}(\alpha,\beta,\gamma)=\mathbf{R}_x(\alpha)\mathbf{R}_y(\beta)\mathbf{R}_z(\gamma) This is called Euler angles.

For a vector v\mathbf{v}, and a random rotation axis (through origin) unit vector k\mathbf{k}, we rotate v\mathbf{v} for angle θ\theta according to the right hand rule, we have: vrot=vcosθ+(k×v)sinθ+k(kv)(1cosθ) \mathbf{v}_{rot}=\mathbf{v}\cos\theta + (\mathbf{k}\times\mathbf{v})\sin\theta+\mathbf{k}(\mathbf{k}\mathbf{v})(1-\cos\theta) In matrix notation, use our cross product matrix: k×v=Kv=[0kzkykz0kxkykx0]v \mathbf{k}\times\mathbf{v}=\mathbf{K}\mathbf{v}= \begin{bmatrix} 0 & -k_z & k_y \cr k_z & 0 & -k_x \cr -k_y & k_x & 0 \end{bmatrix} \mathbf{v} So we can use Rotation Matrix: R=I+(sinθ)K+(1cosθ)K2 \mathbf{R} = \mathbf{I} + (\sin\theta)\mathbf{K}+(1-\cos\theta)\mathbf{K}^2 Note, the rotation axis is always through original point. If we need to rotate around any axis, we can translate it to origin then rotation, and translate it back.

Translation Matrix

In translations (which is not linear transform), without employing homogeneous coordinates, we must add the translation vector directly to our object, rather than simply multiplying by a matrix. By leveraging the additional dimension provided by homogeneous coordinates, we can transform a 3D translation into a 4D linear transformation. P=TP=[100Tx010Ty001Tz0001][XYZ1]=[X+TxY+TyZ+Tz1] \mathbf{P'} = \mathbf{T}\mathbf{P} = \begin{bmatrix} 1 & 0 & 0 & T_x \cr 0 & 1 & 0 & T_y \cr 0 & 0 & 1 & T_z \cr 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \cr Y \cr Z \cr 1 \end{bmatrix}= \begin{bmatrix} X+T_x \cr Y+T_y \cr Z+T_z \cr 1 \end{bmatrix} Now, let's clarify why we assign 1 as the extra dimension for points and 0 for vectors in homogeneous coordinates. This distinction ensures that when we apply a translation to a vector, its direction and magnitude remain unchanged, embodying the principle of Translation Invariance. V=TV=[100Tx010Ty001Tz0001][XYZ0]=[XYZ0] \mathbf{V'} = \mathbf{T}\mathbf{V} = \begin{bmatrix} 1 & 0 & 0 & T_x \cr 0 & 1 & 0 & T_y \cr 0 & 0 & 1 & T_z \cr 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \cr Y \cr Z \cr 0 \end{bmatrix}= \begin{bmatrix} X \cr Y \cr Z \cr 0 \end{bmatrix} Now we can do calculation: vector+vector=vector \mathbf{vector} + \mathbf{vector} = \mathbf{vector}

point+vector=point \mathbf{point} + \mathbf{vector} = \mathbf{point}

pointpoint=vector \mathbf{point} - \mathbf{point} = \mathbf{vector}

point+point=mid point \mathbf{point} + \mathbf{point} = \mathbf{mid\ point}

Affine Transformation

In general, combine with linear transform and translation transform, we have affine transform: P=AP=[SxSrxySrxzTxSryxSySryzTySrzxSrzySzTz0001][XYZ1]=[SxX+SrxyY+SrxzZ+TxSyY+SryxX+SryzZ+TySzZ+SrzxX+SrzyY+Tz1] \mathbf{P'} = \mathbf{A}\mathbf{P} = \begin{bmatrix} S_x & Sr_{xy} & Sr_{xz} & T_x \cr Sr_{yx} & S_y & Sr_{yz} & T_y \cr Sr_{zx} & Sr_{zy} & S_z & T_z \cr 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X \cr Y \cr Z \cr 1 \end{bmatrix}= \begin{bmatrix} S_xX+Sr_{xy}Y + Sr_{xz}Z+T_x \cr S_yY+Sr_{yx}X + Sr_{yz}Z+T_y \cr S_zZ+Sr_{zx}X + Sr_{zy}Y+T_z \cr 1 \end{bmatrix} It's important to note that matrix multiplication does not satisfy the commutative law. However, it does adhere to the associative law. This also implies that we can combine a series of simple affine transformations into a single matrix, streamlining the process. P=An(...(A2(A1P)))=(An...A2A1)P=MP \mathbf{P'} = \mathbf{A_n}(...(\mathbf{A_2}(\mathbf{A_1}\mathbf{P}))) = (\mathbf{A_n}...\mathbf{A_2}\mathbf{A_1})\mathbf{P}=\mathbf{M}\mathbf{P} This approach allows us to expedite calculations by decomposing complex transformations into simpler ones. For instance, to rotate an object by an angle θ\theta around a point T=[Tx,Ty,Tz,1]T\mathbf{T}=[T_x,T_y,T_z,1]^T, we can first translate it back to the origin, apply the rotation, and then translate it back to its original position. P=(TRθT)P \mathbf{P'} = (\mathbf{T}\mathbf{R_\theta}\mathbf{-T})\mathbf{P}

Orthogonal Matrix

For a real square matrix, if we have: QTQ=QQT=I \mathbf{Q}^T\mathbf{Q}=\mathbf{Q}\mathbf{Q}^T=\mathbf{I} Then, we call Q\mathbf{Q} is orthogonal if: QT=Q1 \mathbf{Q}^T=\mathbf{Q}^{-1} For example, if we rotate an object by θ-\theta, there is no difference than a reverse rotation of θ\theta. So rotation matrix is orthogonal.