# Why do transformation matrices always have an extra dimension? [duplicate]

In 3D math I always see matrices with one additional dimension. For example, in 3D graphics, matrices are always 4x4 and in 2d they are 3x3 matrices. Can anyone explain why?

## marked as duplicate by Alexandre Vaillancourt♦Jul 16 '18 at 15:19

This is a facet of the math of affine transformations crammed into a single matrix.

In an affine transformation you have the equation: x' = Ax + b, where x is the original vector, A is the transformation matrix, and b is the translation vector.

To combine A and b into a single matrix requires some extra work. Namely, we must be sure that we can "turn off" the translation when transforming a geometric vector (they have no position in space and hence cannot move) but still apply it when transforming a geometric point (which is nothing but a position in space).

The trick is to put the translation into a fourth column on the transformation matrix as well as adding an additional component to the vectors themselves. This additional component is 1 for geometric points and 0 for geometric vectors. The math of the matrix multiply then works out that the translation components are multiplied by 1 (the identity) for geometric points and added to the final result after rotation/scaling, while the components are multiplied by 0 for geometric vectors and hence nothing is added to the final result.

Explanation with pictures and math examples: https://medium.com/hipster-color-science/computing-2d-affine-transformations-using-only-matrix-multiplication-2ccb31b52181

• Are these just projective coordinates, or is something else going on? – Carsten S Jul 16 '18 at 9:54
• @CarstenS Something like it. Positional space is the hyperplane w = 1 in 4D xyzw-coordinates (i.e. they have x, y and z coordinates as expected, and fourth coordinate equal to 1). What we perceive as translations is really a shear along that hyperplane. Displacements, velocities and the like live in the w = 0 hyperplane, where the aforementoined shears do nothing. This allows any transformation to be a single matrix-vector multiplication, instead of first a multiplication, then maybe an addition if the vector has the right interpretation, which you also need to keep track of somehow. – Arthur Jul 16 '18 at 10:51
• The way I've always thought about the situation is like this: Transformation matrices can only do linear transformations, but translation isn't a linear operation wrt to the original object's space coordinates. However in the next higher dimension it is linear. So an extra constant component with a value of 1 is (at least logically) added to input points, which then allows them to then be used to applying matrices of the next higher dimension. Afterwards the extra coordinate in the resulting vector is simply ignored or discarded. – martineau Jul 16 '18 at 14:38
• I really miss one essential word in the this answer so far: "homogeneous". See the wiki page about this. – AvD Jul 16 '18 at 15:16