Matrix transformations
Another way to write transformations mathematically is in terms of a matrix, which is a
rectangular encoding of the transformation. You can think of this as merging the mapping
vectors for each axis into a single block. When we do this we normally write the vectors in
column, rather than row, fashion. For example, for the transformation above, the two
vectors would have 3 elements and the matrix would have 3×3 elements:
The way to read this is that the first element (x′) of the output vector on the left is found by
adding up the element-by-element multiplication of the first row of the matrix with the
input vector on the right; ax + dy + gz, and so on for the other two elements y′, z′.
There is a special transformation, the identity matrix, which transforms vectors to
themselves (i.e. causes no change at all):
The advantage of this matrix notation is that the composition of two transformations
(applying one after the other) becomes easier to manage. For example, if we have a second
transformation:
then the composition of both transformations is:
The final matrix is said to be the product of the two initial matrices. The element at an
arbitrary cell location (m,n), the cell that lies in both row m and in column n, in the final
matrix is the sum of the element-wise product of row m in the first matrix and column n in
the second matrix.
4
Note that when applying two transformations it is important to apply
them in the correct order; usually you cannot swap matrices. For example, a rotation of
90° about the x axis then a rotation of 90° along the y axis is not the same as doing the
rotations in the opposite order.
Mathematicians have introduced a succinct notation for vectors and matrices, by hiding
all of their internal elements, which makes the product formula look clearer. So instead of
writing (x,y,z) we write this with a single letter, say w:
and similarly for w′ and w″. In Python this could be implemented as a list (or tuple) and
we would have x = w[0], y = w[1] and z = w[2]. The matrices would also be written with
single letters, for example, T:
The transformation from w=(x,y,z) to w′=(x′,y′,z′) is then written simply, with implied
matrix multiplication, as:
w′ = T w
and the composition of two transformations, T and T′, is then:
w″ = T′ T w
which can also be described as the outcome of the first transformation (w′) being applied
to the second:
w″ = T′ w′
or in terms of a new transformation (T′′) that combines both:
w″ = T″ w
Here T″ is defined as the product of the matrices
5
T′ and T. This means that the value of T″
at cell location (m,n) is the sum of the element-wise product of row m of T′ and column n
of T. In Python, these matrices could be implemented as lists of lists.
The identity matrix is commonly denoted by the letter I:
If we have a transformation T, then the inverse transformation T
‒1
is the one such that the
product matrix is the identity matrix:
T T
−1
= I
An inverse does not necessarily exist for a transformation matrix (e.g. projecting a volume
on to a line), but if it does then it is unique and it also acts as an inverse from the other
side:
T
−1
T = I
The example we have used here has been in terms of vectors of size 3 and 3×3
matrices. However, the whole thing generalises and indeed the matrices do not even have
to be square, although if they are not square then they do not have a (proper) inverse. So if
we wanted to project a 3D shape, say, from its (x,y,z) coordinates to a representation in
terms of the coordinates (x,y) on a computer screen, then we could use a 2×3 matrix:
Do'stlaringiz bilan baham: |