To translate a vector by 10 unit in the X direction, why do we have to use a matrix?
We can just add 10 to the mat, and we got the same result too.
Yes, you can add a vector in the case of translation. The reason to use a matrix boils down to having a uniform way to handle different combined transformations.
For example, rotation is usually done using a matrix (check @MickLH comment for other ways to deal with rotations), so in order to deal with multiple transformations (rotation/translation/scaling/projection...etc) in a uniform way, you need to encode them in a matrix.
Well, more technically speaking; a transformation is mapping a point/vector to another point/vector.
where p` is the transformed point and T(p) is the transformation function.
Given that we don't use a matrix we need to do this to combine multiple transformations:
Not only can a matrix combine multiple types of transformations into a single matrix (e.g. affine, linear, projective).
Using a matrix gives us the opportunity to combine chains of transformations and then batch multiply them. This saves us a ton of cycles usually by the GPU (thanks to @ChristianRau for pointing it out).
It's also good to point out that GPUs and even some CPUs are optimized for vector operations; CPUs using SIMD and GPUs being data driven parallel processors by design, so using matrices fits perfectly with hardware acceleration (actually, GPUs were designed to fit matrix/vector operations).
If all you are ever going to do is move along a single axis and never apply any other transformation then what you are suggesting is fine.
The real power of using a matrix is that you can easily concatenate a series of complex operations together, and apply the same series of operations to multiple objects.
Most cases aren't that simple and if you rotate you object first, and want to transform along its local axes instead of the world axes you'll find you can't simply add 10 to one of the numbers and have it work out correctly.
the reason to use a 4x4 matrix is so that the operation is a linear transformation. this is an example of homogeneous coordinates. The same thing is done in the 2d case (using a 3x3 matrix). The reason for using homogeneous coordinates is so that all 3 geometric tansformations can be done using one operation; otherwise one would need to do a 3x3 matrix multiply and a 3x3 matrix addition (for the translation). this link from cegprakash is useful.
To succinctly answer the "why" question, it's because a 4x4 matrix can describe rotation, translation, and scaling operations all at once. Being able to describe any of these in a consistent manner simplifies a lot of things.
Different kinds of transformations can be more simply represented with a different mathematical operations. As you note, translation can be done just by adding. Uniform scaling by multiplying by a scalar. But an appropriately crafted 4x4 matrix can do anything. So using 4x4's consistently makes code and interfaces much simpler. You pay some complexity in understanding these 4x4's, but then lots of things get easier and faster because of it.
See this video to understand the concepts of model, view and projection.
4x4 matrices are not just used for translating a 3D object. But also for various other purposes.
See this to understand how the vertices in the world are represented as 4D Matrices and how they are transformed.
Why matrices can be used?
Many modeled objects (e.g. a car chassis) or part of modeled objects (e.g. a car tire, a driving wheel) are solids: the distances between vertexes never change.
The only transformations we want to do to on them are rotations and translations.
Matrix multiplication can encode both rotations and translations.
Rotation matrices have explicit formulas, e.g.: a 2D rotation matrix for angle
Translations are less trivial and will be discussed later. They are the reason we need 4D matrices.
Why is it cool to use matrices?
Because the composition of multiple matrices can be pre-calculated by matrix multiplication.
E.g., if we are going to translate one thousand vectors
for each vector, we can pre-calculate:
and then do just one multiplication for every vertex:
Even better: if we then want place the vertexes of tire and driving wheel relative to the car, we just multiply the previous matrix
This naturally leads to maintaining a stack of matrices:
Translations cannot be represented by 3D matrices
A simple argument is that translation can take the origin vector:
away from the origin, say to
But that would require a matrix such that:
But that is impossible.
Another argument is the Singular Value Decomposition theorem, which says that every matrix can be made up with two rotation and one scaling operation. No translations there.
How adding one dimension solves the problem
Let's consider the case from 1D to 2D which is easier to visualize.
A matrix in 1D is just one number, and as we've seen in 3D it can't do a translation, only a scaling..
But if we add the extra dimension as:
and we then forget about the new extra dimension, we get:
as we wanted.
This 2D transformation is so important that it has a name: shear transformation.
It is cool to visualize this transformation:
Note how every horizontal line (fixed
We just happened to take the line
Things are analogous in 3D, with 4D shear matrices of the form:
And our old 3D rotations / scaling are now of form:
This Jamie King video tutorial is also worth watching.
Affine space is the space generated by all our 3D linear transformations (matrix multiplications) together with the 4D shear (3D translations).
If we multiply a shear matrix and a 3D linear transformation, we always get something of the form:
This is the most general possible affine transformation, which does 3D rotation / scaling and translation.
One important property is that if we multiply 2 affine matrices:
we always get another affine matrix of form:
Mathematicians call this property closure, and is required to define a space.
For us, it means that we can keep doing matrix multiplications to per-calculate final transformations happily, which is why use used matrices in the first place, without ever getting more general 4D linear transformations which are not affine.
But wait, there is one more important transformation that we do all the time:
First get some intuition about
If only we allowed more general 4-vectors of type:
If we throw away
which is exactly what we wanted! We can verify that for some values, e.g.:
Note how the
The mathematical "trickery" of adding the
See also: related Stack Overflow question: http://stackoverflow.com/questions/2465116/understanding-opengl-matrices
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?