# Matrices

A matrix is a rectangular array of numbers called elements. We can use them to solve linear algebra equations but more commonly they are used to store and manipulate changes made to objects in virtual space as in animated films and computer games graphics.

We may view any 3 dimensional object in virtual space as constructed from many joined up points. Such points are used to give the object its shape and appearance. For example a simple two dimensional object like a triangle would be constructed from 3 points. We could then apply a colour to that shape giving it appearance.

Transformations are changes made to such an object. We may translate (relocate) an object, we may change its orientation relative to other objects, reflect it making it appear as if viewed in a mirror, dilate it so that its apparent size changes or we might distort it. All can be done by matrices.

In our diagram each triangle point is multiplied by the same matrix. The three new points are then used to reconstruct the triangle on the left. It is as if we had taken the triangle and rotated it 90 degrees counter clockwise about the coordinate origin. But be clear even the most convincing of graphics motions are apparent. They are nothing more than the rapid and repeated reconstruction of objects as determined by the repeated changing and applying of transformation matrices to object points.

How did we do the multiplication? The number we put in row n column m of the output matrix was the sum of the numbers in row n multiplied by like position numbers in column m.

Of course most graphic applications are about viewing a changing 3d scene. The matrices used are generally of the 4 column x 4 row type and as such they are capable of both holding the data about an objects current transformed state in the scene or about the transformations that are to be applied to the object.

Matrix addition requires that the numbers of rows and columns are the same. Using the

We could have written the 1’s in the transforming matrix as sin 90’s and the 0’s as cos 90’s. The result would have been the same. By then replacing the sin 90’s with sin θ’s and the cos 90’s with cos θ’s we could rotate the object through any angle of our choosing.

Every object in a virtual scene is built from shapes with applied appearance. Such object shapes are constructed from points in space established using coordinate systems. As a matter of convenience every object in a scene can have its own local coordinate system mapped to the scenes global coordinate system. However where there are linked child and parent objects ( think of fingers as children of hands, hands as children of arms and arms as children of a human torso) each child object will have its own coordinate system linked to that of its immediate parent in a hierarchical fashion, leading eventually back to the scenes global coordinate system. The impression of motion is created by repetitively rebuilding a scene in which tiny transformations are applied to object points.

In computer graphics involving 3d scenes the programmer’s program determines the transform matrix that is to be used and the computer does all the hard work of determining all the new object points and thereby creating the changed or changing image. Action matrices are generally of the four by four type as illustrated.

If an object has undergone a transformation and you have the transform result you can apply another transform to that result to get a transform of a transform. Alternatively you may wish to combine two transforms. Both of these are achieved by matrix multiplication but be aware that the order of multiplication is important as the result of reversing the order does not produce the same result.

Adding and subtracting of like row column matrices is just a case of adding or subtracting the numbers in like array positions together. Scaling of a matrix involves multiplying every element in the matrix by the scaling factor. The inverse of a matrix is that matrix which will undo the transformation that the matrix makes.

The determinant of a matrix is about the effect that a linear transformation has on the areas and volumes of an object. In my blog on vectors we derived the cross product of two vectors A with components (Ax, Ay, Az) and and B with components (Bx, By, Bz) as under and said that the 3 x 3 matrix opposite was a way of showing in matrix form this cross product.
A x B = = i ( Ay Bz – Az By ) – j( Ax Bz – Az Bx) + k( Ax By – Ay Bx )

What we did not say is that we get the cross product from this matrix using the procedure we use to get the determinant of a numerical 3 x 3 matrix. The procedure is as follows. We write down the i and ignoring other entries in its row and column multiply it by the determinant of the 2 x 2 matrix (Ay Bz – Az By) that remains. Next we write down -j and ignoring other entries in its row and column multiply it by the determinant of the 2 x 2 matrix (Ax Bz – Az Bx) that remains. Finally we write down +k and ignoring other entries in its row and column multiply it by the determinant of the 2 x 2 matrix ( Ax By – Ay Bx ) that remains. What we have obtained using this determinant method is the cross product as derived in the previous paragraph.

Consider the 4 x 4 transform matrix shown. The bottom row of d h l and p will in most cases have the numerical values 0, 0, 0 and 1 . The m, n and o values will represent the translations the object is to undergo along the x, y and z axes or the actual position the object is located at. The top left 3 x 3 values are all about the rotations that points on the object will make in 3 dimensional space.

Posted on