First, consider a 2D case, rotate around Origin [0,0] and anti-clockwise θ. R(θ)=[cosθsinθ−sinθcosθ] Then in 3D, we can consider as 3 similar rotation around X,Y,Z-axis by angle θ
Rotation around the X-axis by an angle θ
Rx(θ)=10000cosθsinθ00−sinθcosθ00001
Rotation around the Y-axis by an angle θ
Ry(θ)=cosθ0−sinθ00100sinθ0cosθ00001
Note: here the −sinθ is in Rzx and and sinθ in Rxz. That's because in our coordinates, Y=Z×X.
Rotation around the Z-axis by an angle θ
Rz(θ)=cosθsinθ00−sinθcosθ0000100001
Rotation in 3D can be composed by 3 Rotations around each axis. Rxyz(α,β,γ)=Rx(α)Ry(β)Rz(γ) This is called Euler angles.
For a vector v, and a random rotation axis (through origin) unit vector k, we rotate v for angle θ according to the right hand rule, we have: vrot=vcosθ+(k×v)sinθ+k(kv)(1−cosθ) In matrix notation, use our cross product matrix: k×v=Kv=0kz−ky−kz0kxky−kx0v So we can use Rotation Matrix: R=I+(sinθ)K+(1−cosθ)K2 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=100001000010TxTyTz1XYZ1=X+TxY+TyZ+Tz1 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=100001000010TxTyTz1XYZ0=XYZ0 Now we can do calculation: vector+vector=vector
point+vector=point
point−point=vector
point+point=midpoint
Affine Transformation
In general, combine with linear transform and translation transform, we have affine transform: P′=AP=SxSryxSrzx0SrxySySrzy0SrxzSryzSz0TxTyTz1XYZ1=SxX+SrxyY+SrxzZ+TxSyY+SryxX+SryzZ+TySzZ+SrzxX+SrzyY+Tz1 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 This approach allows us to expedite calculations by decomposing complex transformations into simpler ones. For instance, to rotate an object by an angle θ around a point T=[Tx,Ty,Tz,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
Orthogonal Matrix
For a real square matrix, if we have: QTQ=QQT=I Then, we call Q is orthogonal if: QT=Q−1 For example, if we rotate an object by −θ, there is no difference than a reverse rotation of θ. So rotation matrix is orthogonal.