-
-
Notifications
You must be signed in to change notification settings - Fork 4
A.03 Transformations
In graphics applications it's common to scale, rotate, and translate the objects of the scene before displaying them on screen. For example, let's say you want to move a mesh to another position. You need to move all the vertices of the mesh by performing a matrix multiplication of each vertex position
That is,
Now, it’s interesting how we can visualize it in two different ways. Obviously, we can translate

The same applies if you want to rotate or scale a vertex position. As we will see in this tutorial, transformations of vectors and change of coordinate systems are mathematically equivalent. That is, if you want to transform an object you can transform its frame of reference, and vice versa.
A transformation
In appendix 01 we showed that a bound vector
where
where

Then, it can be stated that applying a linear transformation to a vector
where
That’s exactly what we have seen in appendix 02. Indeed, if we perform the multiplication between the row vector
We just found that to transform a vector
where
However, we can also see

Here we have a vector
As we know, this is the diagonal of the parallelogram defined by the vectors
That is, the coordinates of
At this point, it should be no surprise that the inverse
Observe that in the equation
In a 3D Cartesian coordinate system we can scale vectors with respect to three directions by scaling the related components. That is, given a scaling
The scaling is uniform if the scaling factors are equal
$S(\mathbf{u}+\mathbf{v})=\big( s_x(u_x+v_x),\ s_y(u_y+v_y),\ s_z(u_z+v_z) \big)=$
$(s_xu_x+s_xv_x,\ s_yu_y+s_yv_y,\ s_zu_z+s_zv_z)=$
$(s_xu_x,\ s_yu_y,\ s_zu_z)+(s_xv_x,\ s_yv_y,\ s_zv_z)=$
$S(\mathbf{u})+S(\mathbf{v})$
$S(k\mathbf{v})=(s_xkv_x,\ s_ykv_y,\ s_zkv_z)=$
$k(s_xv_x,\ s_yv_y,\ s_zv_z)=$
$kS(\mathbf{v})$
We know that a linear transformation can be associated with a matrix whose rows are the transformed standard basis vectors. In 3D Cartesian coordinate systems, we have
Then, the matrix
We refer to this matrix as scaling matrix. So, we can scale every 3D vector by simply multiplying it with
Example:
Given a minimum point
To scale the square we need to multiply both
The following illustration shows the result of these transformations

A rotation is a linear transformation, but we won’t provide a formal proof here because it is simpler to observe that the rotation of the sum of two vectors (that is, the rotation of the diagonal of the parallelogram defined by the two vectors) is equivalent to the sum of rotations of the two vectors (that is, the diagonal of the rotated parallelogram). At the same time, rotating a uniformly scaled vector is equivalent to rotate a vector before uniformly scaling it.

Finding the matrix associated with a rotation is a little trickier this time. However, without loss of generality, we will consider
Now consider the left side of the following illustration.

As we know,
where
Then,
That is,
In a similar way, the orthogonal projection of
Then, we have that
Now, we can compute
As you can see,
where
where
For example, if we want to rotate about the x-, y- and z-axes, we need to set
Example:
Given a minimum point
To rotate the square we need to multiply

You can easily verify that the rows of
Now we know how to scale and rotate vectors, but we also need to move points. Maybe you've already heard (or read) about a transformation called translation that allows to relocate objects. However, when you need to move vectors, two problems arise:
-
we certainly want to move points (vertex positions) as we need to relocate meshes. However, for free vectors this transformation doesn’t make any sense since direction and magnitude don’t change after a translation (the point of application for a free vector is irrelevant). So, we need to distinguish between points and vectors.
-
moving a point can’t be expressed as a linear combination of the standard basis vectors. That is, a translation is not a linear transformation, so you can’t associate a
$3\times 3$ matrix with a translation. Fortunately, we can get around this problem to include translations in our matrix equation$\mathbf{w}=\mathbf{vM}$ .
Affine transformations extend linear ones by adding translations. In the next section we are going to introduce this type of transformation, trying to solve the above issues.
Applying a translation
For example, given a 2D point

At the same time, we can translate the frame by using the same displacement vector

So, it seems that translation of vectors and translation of coordinate systems are mathematically equivalent (in the next section we will formally prove that this is true in general for affine transformations). This means that we can translate a frame to apply the same transformation to a vector. So far so good, but the question is: can we find a
$T(\mathbf{u}+\mathbf{v})=(u_x+v_x+t_x,\ u_y+v_y+t_y,\ u_z+v_z+t_z)$
while
$T(\mathbf{u})+T(\mathbf{v})=(u_x+t_x,\ u_y+t_y,\ u_z+t_z)+(v_x+t_x,\ v_y+t_y,\ v_z+t_z)=$
$(u_x+v_x+2t_x,\ u_y+v_y+2t_y,\ u_z+v_z+2t_z)$
Then,
However, we can still find a way to include translations in our matrix equation
As we already know, homogeneous coordinates introduce an "extra" coordinate. This means that in 3D Cartesian systems we step into the 4-th dimension. Fortunately, we just pop in to pick up what we need, and leave immediately after.
A point in 3D space can be represented in homogeneous coordinates by the tuple
Points:
Vectors:
We need this distinction between points and vectors as we want to apply translations to points without affecting vectors. Now, since we are using four components, we can try to find a
Let’s see what happens if we multiply a generic point
That’s exactly the definition of
The vector
However, we'd like to include linear transformations as well. For this purpose, we can try to embed the
Now, if we multiply a generic vector
where
As you can see, the translation doesn’t affect the vector, and the result is the same we showed in equation
On the other hand, if we multiply a generic point
Here we transform
which is a vector, as it’s not a bound to the origin of the frame of reference (see the illustration below, on the left). On the other hand, the sum of two points is a point as well, but it doesn’t make any sense geometrically (unlike the sum of two vectors, which is the resultant force, direction or speed).

Then,
Imagine you want to scale, rotate and translate a vector
The vector
In a vector by matrix multiplication we need to perform
However, thanks to the associative property of matrix multiplication we can write
Now, we have two matrix by matrix multiplications and a vector by matrix multiplication.
Each matrix by matrix multiplication needs
It seems that we need more operation to perform if we first multiply the matrices. However, imagine you want to transform 10 thousand vectors by the same matrices
Then, it is strongly recommended to transform vectors with a matrix which is a composition of all the transformations you want to apply to the vectors.
[1] Practical Linear Algebra: A Geometry Toolbox (Farin, Hansford)
If you found the content of this tutorial somewhat useful or interesting, please consider supporting this project by clicking on the Sponsor button. Whether a small tip, a one time donation, or a recurring payment, it's all welcome! Thank you!