Linear Transformation

## Matrix Representation

While working with libraries like OpenGL, matrices are represented as a 16-element array. There are two representations, row- or column-major and this indicates how elements are stored and manipulated. So if a translation matrix looks like this: For OpenGL, which uses column-major style, elements , , and are accessed with indices 13, 14, and 15. In a system that uses row-major style, these same elements will be accessed with indices 3, 7, and 11. The code fragments below uses column-major style.

## Matrix Multiplication

Finding matrix product of two matrices and involves calculating for each element: In C code this translates to a function like:

void Multiply( const float* A, float* B ) { float t; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; t = A * B + A * B + A * B + A * B; // result overwrites B memcpy(B, t, sizeof(float) * 16); } 

## Transforms

Apply transforms is the same as multiplying with the corresponding transformation matrices.

### Translate

To move by a translation vector : ### Scale

To scale by a factor in each axis: ### Rotate

Basic rotations about the x, y, and z axes: rotates the y-axis towards the z-axis rotates the z-axis towards the x-axis rotates the x-axis towards the y-axis

To rotate radians about an arbitrary, normalized axis : where and ### Shear

To apply shear along x-, y-, or z-axis, modify the coefficients below: ## References

1. Akenine-Moller, Tomas and Eric Haines, Real-Time Rendering 2nd Edition, A K Peters: 42-43, 725. Document is accessible from http://www.puchu.net. © 2002-2010 Sean Yang, Karen Yang, Don Yang and/or respective authors, all rights reserverd. This material may contain (biased) opinions, inappropriate materials for numerous individuals, work of other authors from the internet, links that refer to other web documents and resources, or origial work that cannot be use for personal or commercial purposes. Please respect the work of original authors.