Computer Graphics Review


§ Matricies

Transformation

Let T∈R4×4,p∈R4×1,p′∈R4×1T \in \mathbb{R}^{4 \times 4}, p \in \mathbb{R}^{4 \times 1}, p' \in \mathbb{R}^{4 \times 1}. Then, a transformation may be expressed via

Tp=p′,Tp = p',

where TT is our transformation matrix, pp and p′p' are our 3D position in homogeneous coordinates before and after transformation by TT, respectively.

In the case of a composition of transformations, i.e. let A1,A2,…,An−1,An∈R4x4A_1, A_2, \dots, A_{n - 1}, A_n \in \mathbb{R}^{4x4} be transformations, then

p′=AnAn−1…A2A1pp' = A_n A_{n-1} \dots A_2 A_1 p

is composed from right to left, i.e.

p′=An(An−1(…(A2(A1(p)))))p' = A_n(A_{n-1}(\dots (A_2(A_1(p)))))

§ Matrix Stack

Sps. we had two functions defining a square and triangle in model space:

Then, we can draw the following examples

Target Pseudocode

DrawHouse(MV)
{
    MV.Push()
    DrawSquare(MV)
    MV.Translate(0, 1)
    DrawTriangle(MV)
    MV.Pop()
}

Target Pseudocode

DrawHouse2(MV)
{
    // big house
    MV.Push()
    DrawSquare(MV)
    MV.Translate(0, 1)
    DrawTriangle(MV)
    MV.Pop()
    // small house
    MV.Push()
    MV.Translate(3, 0)
    MV.Scale(0.5, 0.5);
    MV.Translate(1, 1)
    DrawHouse(MV)
    MV.Pop()
}

In this example, the point (3.5,1.5)(3.5, 1.5) has world coordinates wp⃗=(3.5,1.5,1)T{}^w\vec{p} = (3.5, 1.5, 1)^T and model coordinates mp⃗=(0,1,1)T{}^m\vec{p} = (0, 1, 1)^T.

For the DrawHouse2(MV) example, there exists a matrix MM satisfying wp⃗=M mp⃗{}^w\vec{p} = M\,{}^m\vec{p}, i.e.

(3.51.51)=(103010001)⏟Translate(3,0)(0.50000.50001)⏟Scale(0.5,0.5)(101011001)⏟Translate(1,1)(100011001)⏟Translate(1, 0)(011)⏟mp⃗\begin{pmatrix} 3.5\\1.5\\1 \end{pmatrix} = \underbrace{\begin{pmatrix} 1 & 0 & 3\\ 0 & 1 & 0\\ 0 & 0 & 1 \end{pmatrix}}_{\scriptsize\verb|Translate|(3, 0)} \underbrace{\begin{pmatrix} 0.5 & 0 & 0\\ 0 & 0.5 & 0\\ 0 & 0 & 1 \end{pmatrix}}_{\scriptsize\verb|Scale|(0.5, 0.5)} \underbrace{\begin{pmatrix} 1 & 0 & 1\\ 0 & 1 & 1\\ 0 & 0 & 1 \end{pmatrix}}_{\scriptsize\verb|Translate|(1, 1)} \underbrace{\begin{pmatrix} 1 & 0 & 0\\ 0 & 1 & 1\\ 0 & 0 & 1 \end{pmatrix}}_{\scriptsize\verb|Translate(1, 0)|} \underbrace{\begin{pmatrix} 0\\ 1\\ 1 \end{pmatrix}}_{\scriptsize{}^m\vec{p}}

There are two ways to think about these transformations, depending if we read left to right or right to left.