Home | Gaming | Programming | Play Online | Contact | Keyword Query  GAMES++ BROWSER UTILITIES SITE SEARCH
 Web Games++ AFFILIATES   # Transforming a Vector by a Matrix Part 4: Matrix Transformation Tutorial

### 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 + y0 * matrix + z0 * matrix +
w0 * matrix;

y = x0 * matrix + y0 * matrix + z0 * matrix +
w0 * matrix;

z = x0 * matrix + y0 * matrix + z0 * matrix +
w0 * matrix;
``````

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 + y0 * matrix + z0 * matrix +
matrix;

y = x0 * matrix + y0 * matrix + z0 * matrix +
matrix;

z = x0 * matrix + y0 * matrix + z0 * matrix +
matrix;
``````

These are the formulas you should use to transform a vector by a matrix.