Skip to content
PostComputer Graphics / Lecture

CG-Modeling Transformation

2025-03-01
Back to Blog

Computer Graphics - Transformation include the following topics: Linear Transformation, Homogeneous Coordinates, Affine Transformations, Inverse Transform, Composing Transform, 3D Transformations, Rodrigues' Rotation Formula.


CG-Modeling Transformation ​

Linear Transformation ​

Scale Matrix ​

zLEuNc

[x′y′]=[sx00sy][xy]

Reflection Matrix ​

yzwFEy

Horizontal reflection:

  • x′=−x
  • y′=y
[x′y′]=[−1001][xy]

Shear Matrix ​

LOFKoE

  • Horizontal shift is 0 at y=0
  • Horizontal shift is a at y=1
  • Vertical shift is always 0
[x′y′]=[1a01][xy]

Rotation Matrix ​

M0PdYf

Rθ=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]R−θ=Rθ−1=RθT

Homogeneous Coordinates ​

Add a third coordinate (w-coordinate): ​

  • 2D point:p=(x,y,1)T
  • 2D vector:v=(x,y,0)T

Valid operations if w-coordinate of result is 1 or 0: ​

  • vector + vector = vector
  • point − point = vector
  • point + vector = point
  • point + point = ??
[xyw] is the 2D point [xwyw1],w≠0
[x′y′w′]=[10tx01ty001][xy1]=[x+txy+ty1]

Affine Transformations ​

Affine map = linear map + translation: ​

[x′y′]=[abcd]⋅[xy]+[txty]

Using homogeneous coordinates: ​

[x′y′1]=[abtxcdty001]⋅[xy1]

Scale: ​

S(sx,sy)=[sx000sy0001]

Rotation: ​

R(α)=[cos⁡α−sin⁡α0sin⁡αcos⁡α0001]

Translation: ​

GDBFNF

T(tx,ty)=[10tx01ty001]

Inverse Transform ​

M−1M−1 is the inverse of transform M in both a matrix and geometric sense.

xxvNp0

Composing Transform ​

Transform Ordering Matters!

Matrix multiplication is not commutative: ​

R45⋅T(1,0)≠T(1,0)⋅R45

Note that matrices are applied right to left: ​

T(1,0)⋅R45⋅[xy1]=[101010001]⋅[cos⁡45∘−sin⁡45∘0sin⁡45∘cos⁡45∘0001]⋅[xy1]

Sequence of Affine Transforms ​

  • Compose by matrix multiplication
  • Very important for performance!
An(…A2(A1(x)))=An⋅⋯⋅A2⋅A1⋅(xy1)

Pre-multiply n matrices to obtain a single matrix representing the combined transform.

How to rotate around a given point c? ​

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

Ez3SaS

Matrix representation:

T(c)⋅R(α)⋅T(−c)

3D Transformations ​

Use homogeneous coordinates again:

  • 3D point:

    (x,y,z,1)T
  • 3D vector:

    (x,y,z,0)T

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

(xw,yw,zw)

Use 4×4 Matrices for Affine Transformations ​

(x′y′z′1)=(abctxdeftyghitz0001)⋅(xyz1)

Order: Linear transformations, then translation.

Scale ​

S(sx,sy,sz)=(sx0000sy0000sz00001)

Translation ​

T(tx,ty,tz)=(100tx010ty001tz0001)

Rotation ​

Rotation around the x-axis: ​

Rx(α)=(10000cos⁡α−sin⁡α00sin⁡αcos⁡α00001)

Rotation around the y-axis: ​

Ry(α)=(cos⁡α0sin⁡α00100−sin⁡α0cos⁡α00001)

Rotation around the z-axis: ​

Rz(α)=(cos⁡α−sin⁡α00sin⁡αcos⁡α0000100001)

Compose Any 3D Rotation from Rx, Ry, Rz ​

Rxyz(α,β,γ)=Rx(α)Ry(β)Rz(γ)
  • So-called Euler angles
  • Often used in flight simulators: roll, pitch, yaw

Rodrigues' Rotation Formula ​

Rotation by angle α around axis n ​

R(n,α)=cos⁡(α)I+(1−cos⁡(α))nnT+sin⁡(α)NN=(0−nznynz0−nx−nynx0)