HTML and CSS Reference
In-Depth Information
123 123
1
456
4
7
89
7
Figure 18-1. A 3 × 3 matrix, a 1 × 3 matrix, and a 3 × 1 matrix; each uses the rows by columns notation.
Any particular matrix is usually represented by a variable, such as M . To refer to a specific cell in a matrix,
you use the variable name with the row and column number in subscript. For example, if the 3 × 3 matrix
in Figure 18-1 is denoted as M , then using the rows by colums notation, M 2,3 is equal to 6, as it refers to the
second row, third column. Matrix indices start at 1, which is different than the notation for JavaScript
arrays, which start at 0.
The cells of a matrix can contain not only numbers, but also formulas and variables. If you've ever used a
spreadsheet, it is basically one big matrix. You can have one cell hold the sum of a column, and another
cell multiply that sum by some number that's held in another cell, and so on. So, you see that matrices can
be rather useful.
Matrix operations
A spreadsheet is kind of a free-form matrix, but the matrices we use are a lot more structured and have all
kinds of rules for what we can do with them and how to do those things.
There are usually two ways to teach matrix math. The first approach describes how to do the operations in
detail, using matrices full of seemingly random numbers. You learn the rules, but you have no idea why
you are doing certain things or what the result means. It's like playing a game where you arrange the
numbers in a pretty pattern.
The second approach is to describe the contents of the matrices in detail and skim over the operation.
Using vague instructions such as “and then you just multiply these two matrices together and get this …”,
leaving the reader with no idea how this multiplication is done.
In this chapter, we walk the line between these two methods. We start by looking at matrices that contain
meaningful values, and then we see how to manipulate them.
Matrix addition
One of the more common uses of matrices is manipulating 3D points, which contain a value for its x, y,
and z positions. We can easily view this as a 1 × 3 matrix, like so:
x y z
To move this point in space—also called translating the point—you need to know how far to move it on
each axis. You can put this in a translation matrix , which is another 1 × 3 matrix that looks something like
this:
 
Search WWH ::




Custom Search