# Transforming a Vector by a Matrix Part 4: Matrix Transformation Tutorial
### Table of Contents
- Introduction
- Math Prerequisites
- Importance of Correct Transformations
- What a Matrix Represents
- Matrix Multiplication
**Transforming a Vector by a Matrix**
- Object Space Transformations
- Camera Transformations
- Inverse Transformations
- Hierarchical Transformations
- Precision
- Conclusion
### Transforming a Vector by a Matrix
This is the second operation which is required for our matrix
transformations. It involves projecting a stationary vector onto
transformed axis vectors using the dot product. One dot product is
performed for each coordinate axis.
```
x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
w0 * matrix[3][0];
y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
w0 * matrix[3][1];
z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
w0 * matrix[3][2];
```
The x0, y0, etc. coordinates are the original object space coordinates
for the vector. That is, they never change due to transformation.
"Alright," you say. "Where did all the w coordinates come from???"
Good question :) The w coordinates come from what is known as a
homogenous coordinate system, which is basically a way to represent 3d
space in terms of a 4d matrix. Because we are limiting ourselves to
3d, we pick a constant, nonzero value for w (1.0 is a good choice,
since anything * 1.0 = itself). If we use this identity axiom, we can
eliminate a multiply from each of the dot products:
```
x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
matrix[3][0];
y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
matrix[3][1];
z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
matrix[3][2];
```
These are the formulas you should use to transform a vector by a matrix. |