Matrix transposition will come in handy when you get to Chapter 6, Light and Shading. You’ll use it when translating certain vectors (called normal vectors) between object space and world space. This may sound like science fiction, but is crucial to shading your objects correctly.
When you transpose a matrix, you turn its rows into columns and its columns into rows:
Transposing a matrix turns the first row into the first column, the second row into the second column, and so forth. Here’s a test that demonstrates this.
| Scenario: Transposing a matrix |
| Given the following matrix A: |
| | 0 | 9 | 3 | 0 | |
| | 9 | 8 | 0 | 8 | |
| | 1 | 8 | 5 | 3 | |
| | 0 | 0 | 5 | 8 | |
| Then transpose(A) is the following matrix: |
| | 0 | 9 | 1 | 0 | |
| | 9 | 8 | 8 | 0 | |
| | 3 | 0 | 5 | 5 | |
| | 0 | 8 | 3 | 8 | |
And interestingly, the transpose of the identity matrix always gives you the identity matrix. Implement the following test to show that this is true.
| Scenario: Transposing the identity matrix |
| Given A ← transpose(identity_matrix) |
| Then A = identity_matrix |
See? Good, clean fun. Make those tests pass, and then move on. It’s time to talk about matrix inversion.
52.14.85.76