Matricies§

  • Matrices are useful in computer graphics, as they allow us to define transformations within a space.
  • In graphics, 3D objects are often represented by a mesh – a collection of vertices and their connectivity.
  • We assume that connectivity is unchanged under transformation.

Transformation

Let $T \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’, $$

where $T$ is our transformation matrix, $p$ and $p’$ are our 3D position in homogeneous coordinates before and after transformation by $T$, respectively.

In the case of a composition of transformations, i.e. let $A_1, A_2, \dots, A_{n - 1}, A_n \in \mathbb{R}^{4x4}$ be transformations, then

$$ p’ = A_n A_{n-1} \dots A_2 A_1 p $$

is composed from right to left, i.e.

$$ p’ = A_n(A_{n-1}(\dots (A_2(A_1(p))))) $$


Matrix Stack§

  • The first element is the identity.
  • All matrix operations are right multiplied

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

Then, we can draw the following examples

1

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

2

TargetPseudocode
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)$ has world coordinates ${}^w\vec{p} = (3.5, 1.5, 1)^T$ and model coordinates ${}^m\vec{p} = (0, 1, 1)^T$.

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

$$ \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.

  • L->R: Transforming the coordinate system w.r.t. the latest coordinate system
  • R->L: Transforming the vertex w.r.t. the world coordinate system