Wednesday, March 14, 2012

Rotational matrix as an example of Data Driven Design.

Every self respecting linear algebra teach causes students to hate matrices. If you can't you are not qualified. Only now, after three years without formal study of matrices, I learned to appreciate them.

I made a small computer graphics project at school. I had a separate function for X axis rotation, separate function for Y axis rotation, Z rotation and XYZ scaling were separate function, so was XYZ translation. My teacher told me to use matrices but I simply could not understand why it is better. I mean, matrices are creepy and functions are simple. Rotation around arbitrary axis was a bit cheaty (and buggy); this is fine for a small project though.

Now I understand the beauty of matrices. Now I see what is wrong with transformations stored as list of function objects. 8 years ago I was too young to understand the value of simple matrix that replaces arbitrarily long list of functions with parameters.

My friend recently showed me a piece of code from his hobby project. The code was full of conditional and switch cases. After little thought we realized that confusing branching in code can be replaced with a single matrix. It was the most satisfying change I ever made in code.