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∈R4×4,p∈R4×1,p′∈R4×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 A1,A2,…,An−1,An∈R4x4 be transformations, then
p′=AnAn−1…A2A1p
is composed from right to left, i.e.
p′=An(An−1(…(A2(A1(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
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) has world coordinates wp=(3.5,1.5,1)T and model coordinates mp=(0,1,1)T.
For the DrawHouse2(MV)
example, there exists a matrix M satisfying wp=Mmp, i.e.
3.51.51=Translate(3,0)100010301Scale(0.5,0.5)0.50000.50001Translate(1,1)100010111Translate(1, 0)100010011mp011
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