10
$\begingroup$

This is what my lecturer told me in the coursework:

We only consider 4*4 matrices. These are used to rotate, scale or translate objects (or any combination of these operations). Matrices are also used later in the implementation of the virtual camera model. If you do not know the difference between a vector transformation and point transformation, look it up.

I can't seem to find an answer and made an account for this website just for this question.

$\endgroup$
1
  • 1
    $\begingroup$ In complement to all the other answers and because other people already answered this question in length elsewhere you can check: scratchapixel.com/lessons/… $\endgroup$
    – user18490
    Jan 20 '17 at 11:49
9
$\begingroup$

Here's the simple answer.

In 4D, to be able to multiply them by a 4x4 matrix, vectors are represented as (x,y,z,0) and points are represented as (x,y,z,1).

Since the 4th row of a 4x4 matrix represents the translation of the matrix, the above representations make it so points are affected by translation, but vectors are not.

Both vectors and points are affected by the rotation, scaling, etc though.

Caveat:

There is deeper discussion to be had if you expect the vectors to have certain properties. For instance, if you transform a triangle's normal by the same matrix you transform the triangle's vertices, it likely won't actually be the normal vector of that triangle anymore. This is because normal vectors have a sort of inverse relationship to the vertices that they are calculated from.

$\endgroup$
2
  • $\begingroup$ Normals don't work because they're not vectors. Don't know of a good intro to the concept though. $\endgroup$ Nov 24 '16 at 13:14
  • 2
    $\begingroup$ surface normals are bivectors, not vectors. We can find a normal by the cross product of two vectors, the result is a bivector. SEE Per Vogensen's: gist.github.com/pervognsen/c6b1d19754c2e8a38b10886b63d7bf2d $\endgroup$ Jan 18 '17 at 13:55
4
$\begingroup$

From what I've learnt, since I'm also a student, is that you want to work with $4 \times 4$ matrices in order to treat rotations, scaling and translations in the same way, that is, multiplying by a matrix (i.e., a $4 \times 4$ matrix).

Remember that without these $4 \times 4$ matrices, translations would be represented by summing with a vector, whereas rotations and scaling are represented using multiplications with respectively a vector and a scalar factor.

Now the question is: how do we pass from a 3D coordinate systems to a 4D one? The answer is "homogenous coordinates".

So, what does it mean? We construct $4 \times 4$ matrices to represent rotations, scaling and translation, so that we only use matrix multiplications to represent transformations (e.g., rotations, scaling, etc). How we construct them individually, it's more specific, but you can have a look it on the web.

At this point, we have $4 \times 4$ matrices and 3D vectors, not useful yet, because you can't multiply $4 \times 4$ matrices and $3D$ vectors, since the dimensions do not match. That's why, when we work with homegeneous coordinates, we also need to convert our given 3D points into corresponding 4D ones.

How do we do it?

We distinguish between direction and position vectors. Direction vectors, as the name suggests, have a direction at which they are pointing; we also care about their length, but they are not affected by translations, since we don't care about their position. Position vectors (or simply "points") can be translated or moved around; they are usually represented with respect to the origin, i.e. as a vector from the origin to the point itself.

We transform 3D direction vectors by adding a $0$ as the $4$th coordinate of the corresponding homogeneous vector: we add a zero because this basically eliminates the effect of translations. We do a similar thing with position vectors, but instead of a $0$ we add a $1$, for the opposite reason.

For example, if we have a $3D$ direction vector $v = \begin{pmatrix} v_1 \\ v_2 \\ v_3\end{pmatrix}$, we transform it by doing $v' = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \\ 0\end{pmatrix}$. Similarly, if we had a point vector $u = \begin{pmatrix} u_1 \\ u_2 \\ u_3\end{pmatrix}$ we would transform it to $u' = \begin{pmatrix} u_1 \\ u_2 \\ u_3 \\ 1\end{pmatrix}$

Note: to convert from homogeneous coordinates back to corresponding $3D$ ones, you can't simply remove the $4th$ coordinate, unless it's still equal to $1$ (or $0$ respectively).

$\endgroup$
1
  • $\begingroup$ This answer would be more complete if you noted that, in actual homogeneous coordinates, $(wx, wy, wz, w)$ for any $w \ne 0$ is also a valid representation of the point $(x, y, z)$. When converting from ordinary 3D coordinates to 4D projective coordinates, it's convenient to choose $w = 1$, but allowing other values of $w$ in the inverse conversion lets us represent perspective transformations using 4D matrix multiplication, too. $\endgroup$ Nov 20 '16 at 7:24
2
$\begingroup$

If you would look up the definition of a vector and a point, then a vector is:

A quantity, such as velocity, completely specified by a magnitude and a direction. http://www.thefreedictionary.com/vector

And a point is:

A dimensionless geometric object having no properties except location. http://www.thefreedictionary.com/point

So you could say that a vector is a direction with scale, and a point is a location.

So, if you transform a vector you just rotate and scale it. With a point you also translate it (the rotation and scaling of a point is around the origin, since it iss just a location the point itself cannot be rotated).

Most of the times a vector and a point are put into the same container, a vector with 4 components. The only difference is the w component. If the w component is 0, then it is a direction. If it is 1 then the vector is a point.

The reason for this can be found in the matrix itself. It makes use of the way you multiply a vector with 4 components with a 4x4 matrix. If you do not know how that works, I would suggest a quick google.

Most of the times you use a 4x4 matrix. A normal transformation matrix could look like this: \begin{bmatrix}rot+scale&rot+scale&rot+scale&translation\\rot+scale&rot+scale&rot+scale&translation\\rot+scale&rot+scale&rot+scale&translation\\0&0&0&1\end{bmatrix} (The rotation and scale are put in the 3x3 area you could say, so for just rotation and scale a 3x3 matrix could also be used, but when translation comes in, we need that 4th column.)

As you can see, if the last component is 0, then you have a multiplication with 0 and therefore the result is 0 and there is no translation.

This makes it easy in computer graphics with polygonal objects. You have the same transformation matrix to transform the positions but also the normals. Because the normals have their w component set to 0 and the positions' w component is 1, the normals are just rotated (and also scaled which can lead to some weird stuff, so most of the times the normal is normalized after. It isn't actually recommended to use the same matrix for positions and rotations because of the weird stuff! Look at @JarkkoL 's comment.) and the positions are translated (and rotated and scaled around the origin).

Hope I did not make a mistake :P, and this helped you!

$\endgroup$
2
  • 2
    $\begingroup$ Normals are not transformed with the same transformation matrix as positions. You need to calculate inverse of the transpose of the 3x3 sub-matrix to properly transform normals for transformations with non-uniform scaling and/or skewing. $\endgroup$
    – JarkkoL
    Nov 19 '16 at 21:37
  • $\begingroup$ @JarkkoL yeah that is true, you are right with that. It is best to not use the same matrix, but depending on the implementation, it is done. Most of the times people do not care about the skewing of the normals that much, because they either do not use non-uniform scaling or scaling at all. That part about transforming positions and normals was more about that it could be useful to use one container. $\endgroup$
    – bram0101
    Nov 19 '16 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.